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:
Ruslan Ermilov 2001-07-19 08:07:09 +00:00
parent a4c53d9184
commit 1a084f197d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=79939

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