diff options
author | ru <ru@FreeBSD.org> | 2001-07-19 08:07:09 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2001-07-19 08:07:09 +0000 |
commit | 9196524e138a5dea518a781a17ef8997d4e0077f (patch) | |
tree | d45493f65bc83c01389f3c411358f98025ecb86b /usr.bin/banner | |
parent | f2076c0dfdf06f7842d5fd5359b510faff78764d (diff) | |
download | FreeBSD-src-9196524e138a5dea518a781a17ef8997d4e0077f.zip FreeBSD-src-9196524e138a5dea518a781a17ef8997d4e0077f.tar.gz |
Fixed the race caused by not checking the result of fgets(3):
/usr/bin/env MALLOC_OPTIONS=J banner </dev/null
PR: bin/29074
Fixed the problem when banner(6) would eat last character:
echo -n a | banner
MFC after: 1 week
Diffstat (limited to 'usr.bin/banner')
-rw-r--r-- | usr.bin/banner/banner.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/usr.bin/banner/banner.c b/usr.bin/banner/banner.c index c89d433..7134c13 100644 --- a/usr.bin/banner/banner.c +++ b/usr.bin/banner/banner.c @@ -1075,9 +1075,16 @@ main(int argc, char *argv[]) if ((message = malloc((size_t)MAXMSG)) == NULL) err(1, "malloc"); fprintf(stderr,"Message: "); - (void)fgets(message, MAXMSG, stdin); - nchars = strlen(message); - message[nchars--] = '\0'; /* get rid of newline */ + if (fgets(message, MAXMSG, stdin) == NULL) { + nchars = 0; + message[0] = '\0'; + } else { + nchars = strlen(message); + + /* Get rid of newline. */ + if (message[nchars - 1] == '\n') + message[--nchars] = '\0'; + } } /* some debugging print statements */ |