From 1de2a22417da92029923c086c5c3a1fcc1b0d30e Mon Sep 17 00:00:00 2001 From: Ray Lai Date: Sat, 19 Apr 2008 09:22:32 +0000 Subject: 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. --- usr.bin/sendbug/sendbug.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'usr.bin') 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 . @@ -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: -- cgit v1.2.3