From a2897f032fb00167b1844c7f298e128e33527733 Mon Sep 17 00:00:00 2001
From: "Eric S. Raymond" <esr@thyrsus.com>
Date: Sat, 25 Jan 1997 18:29:43 +0000
Subject: Yet another step.

svn path=/trunk/; revision=832
---
 driver.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/driver.c b/driver.c
index 383a2333..35bb3e8c 100644
--- a/driver.c
+++ b/driver.c
@@ -408,9 +408,8 @@ char *realname;		/* real name of host */
 {
     char buf [MSGBUFSIZE+1]; 
     int	from_offs, to_offs, cc_offs, bcc_offs, ctt_offs, env_offs;
-    char *headers, *received_for, *line;
-    int n, oldlen, ch;
-    int sizeticker, delete_ok;
+    char *headers, *received_for;
+    int n, oldlen, ch, sizeticker, delete_ok;
     FILE *sinkfp;
     RETSIGTYPE (*sigchld)();
 #ifdef HAVE_GETHOSTBYNAME
@@ -430,13 +429,10 @@ char *realname;		/* real name of host */
     headers = received_for = NULL;
     from_offs = to_offs = cc_offs = bcc_offs = ctt_offs = env_offs = -1;
     oldlen = 0;
-    line = (char *)NULL;
     for (;;)
     {
-	char *bufp;
+	char *bufp, *line;
 
-	if (line)
-	    free(line);
 	line = xmalloc(sizeof(buf));
 	line[0] = '\0';
 	do {
@@ -463,8 +459,12 @@ char *realname;		/* real name of host */
 	}
 	len -= n;
 
+	/* check for end of headers; don't save terminating line */
 	if (line[0] == '\r' && line[1] == '\n')
-		break;  /* end of message */
+	{
+	    free(line);
+	    break;
+	}
      
 	if (!ctl->no_rewrite)
 	    reply_hack(line, realname);
@@ -489,6 +489,7 @@ char *realname;		/* real name of host */
 	    bufp = headers + oldlen;
 	    oldlen = newlen;
 	}
+	free(line);
 
 	if (from_offs == -1 && !strncasecmp("From:", bufp, 5))
 	    from_offs = (bufp - headers);
@@ -500,9 +501,9 @@ char *realname;		/* real name of host */
 	else if (!strncasecmp("To:", bufp, 3))
 	    to_offs = (bufp - headers);
 
-	else if (env_offs == -1 && !strncasecmp("Apparently-To:", bufp, 14))
-	    env_offs = (bufp - headers);
-	else if (env_offs == -1 && !strncasecmp(ctl->server.envelope, bufp, 14))
+	else if (env_offs == -1 && !strncasecmp(ctl->server.envelope,
+						bufp,
+						strlen(ctl->server.envelope)))
 	    env_offs = (bufp - headers);
 
 	else if (!strncasecmp("Cc:", bufp, 3))
@@ -520,9 +521,6 @@ char *realname;		/* real name of host */
 #endif /* HAVE_RES_SEARCH */
     }
 
-    if (line)
-	free(line);
-
     /*
      * We can now process message headers before reading the text.
      * In fact we have to, as this will tell us where to forward to.
-- 
cgit v1.2.3