diff options
author | 2008-04-19 09:22:31 +0000 | |
---|---|---|
committer | 2008-04-19 09:22:31 +0000 | |
commit | b2c335bb9cd42222736769bca0b92ee87fe21c6f (patch) | |
tree | cf3d7b4729d5e655e1ed2a72b6af091ecc593549 /usr.bin/sendbug/sendbug.c | |
parent | add a driver flag to force the negotiation of SATA 1 transfers (diff) | |
download | wireguard-openbsd-b2c335bb9cd42222736769bca0b92ee87fe21c6f.tar.xz wireguard-openbsd-b2c335bb9cd42222736769bca0b92ee87fe21c6f.zip |
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/sendbug/sendbug.c')
-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: |