diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2008-04-19 09:22:32 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2008-04-19 09:22:32 +0000 |
commit | 1de2a22417da92029923c086c5c3a1fcc1b0d30e (patch) | |
tree | 08c0b7bb7fb2089c3b024f8832c9b01be7851dd9 /usr.bin | |
parent | fee43a053805f4933951b7d78241781f8ae7a500 (diff) |
Decrement len variable after removing newline, prevents copying the
NUL at the end of a string into the mail. Discovered by dasn.
Move newline printing into outer loop, prevents multiple newlines
from appearing if there are multiple comments in a line. Discovered
by okan.
OK okan.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/sendbug/sendbug.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/usr.bin/sendbug/sendbug.c b/usr.bin/sendbug/sendbug.c index 12ad1ba3b56..41deec918a1 100644 --- a/usr.bin/sendbug/sendbug.c +++ b/usr.bin/sendbug/sendbug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sendbug.c,v 1.54 2008/01/04 00:50:09 ray Exp $ */ +/* $OpenBSD: sendbug.c,v 1.55 2008/04/19 09:22:31 ray Exp $ */ /* * Written by Ray Lai <ray@cyth.net>. @@ -433,9 +433,10 @@ send_file(const char *file, int dst) return (-1); lbuf = NULL; while ((buf = fgetln(fp, &len))) { - if (buf[len - 1] == '\n') + if (buf[len - 1] == '\n') { buf[len - 1] = '\0'; - else { + --len; + } else { /* EOF without EOL, copy and add the NUL */ if ((lbuf = malloc(len + 1)) == NULL) goto end; @@ -468,8 +469,7 @@ send_file(const char *file, int dst) copylen = sp - buf; else copylen = len; - if (atomicio(vwrite, dst, buf, copylen) != copylen || - atomicio(vwrite, dst, "\n", 1) != 1) + if (atomicio(vwrite, dst, buf, copylen) != copylen) goto end; if (!ep) break; @@ -477,6 +477,8 @@ send_file(const char *file, int dst) len -= ep - buf + 1; buf = ep + 1; } + if (atomicio(vwrite, dst, "\n", 1) != 1) + goto end; } rval = 0; end: |