aboutsummaryrefslogtreecommitdiffstats
path: root/driver.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1998-01-17 23:59:22 +0000
committerEric S. Raymond <esr@thyrsus.com>1998-01-17 23:59:22 +0000
commit4c7cf4622d813c321959f99c4edbff2e9023952e (patch)
tree54d3299c0fe8c48a8d6dbd1d8cc71eb69b5eec5e /driver.c
parent5c0d2911f5acf09d91789d469bab4c31020d20dd (diff)
downloadfetchmail-4c7cf4622d813c321959f99c4edbff2e9023952e.tar.gz
fetchmail-4c7cf4622d813c321959f99c4edbff2e9023952e.tar.bz2
fetchmail-4c7cf4622d813c321959f99c4edbff2e9023952e.zip
Byrial Jensen's fix to handle NULs.
svn path=/trunk/; revision=1586
Diffstat (limited to 'driver.c')
-rw-r--r--driver.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/driver.c b/driver.c
index af4956fc..82e6f2a0 100644
--- a/driver.c
+++ b/driver.c
@@ -477,17 +477,23 @@ static int stuffline(struct query *ctl, char *buf)
/* ship a line to the given control block's output sink (SMTP server or MDA) */
{
int n;
+ char *last;
+
+ /* The line may contain NUL characters. Find the last char to use
+ * -- the real line termination is the sequence "\n\0".
+ */
+ last = buf;
+ while ((last += strlen(last)) && (last[-1] != '\n'))
+ last++;
/* fix message lines that have only \n termination (for qmail) */
if (ctl->forcecr)
{
- char *cp = buf + strlen(buf) - 1;
-
- if (*cp == '\n' && (cp == buf || cp[-1] != '\r'))
+ if (last - 1 == buf || last[-2] != '\r')
{
- *cp++ = '\r';
- *cp++ = '\n';
- *cp++ = '\0';
+ last[-1] = '\r';
+ *last++ = '\n';
+ *last = '\0';
}
}
@@ -517,17 +523,18 @@ static int stuffline(struct query *ctl, char *buf)
{
char *sp, *tp;
- for (sp = tp = buf; *sp; sp++)
+ for (sp = tp = buf; sp < last; sp++)
if (*sp != '\r')
*tp++ = *sp;
*tp = '\0';
+ last = tp;
}
n = 0;
if (ctl->mda)
- n = fwrite(buf, 1, strlen(buf), sinkfp);
+ n = fwrite(buf, 1, last - buf, sinkfp);
else if (ctl->smtp_socket != -1)
- n = SockWrite(ctl->smtp_socket, buf, strlen(buf));
+ n = SockWrite(ctl->smtp_socket, buf, last - buf);
return(n);
}