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
This commit is contained in:
ru 2001-07-19 08:07:09 +00:00
parent f2076c0dfd
commit 9196524e13

View File

@ -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 */