Date: Wed, 18 Jul 2001 20:30:02 -0700 (PDT) From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/29074: banner seg faults on Ctrl-D Message-ID: <200107190330.f6J3U2M96823@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/29074; it has been noted by GNATS. From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Chad David <davidc@acns.ab.ca> Cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: bin/29074: banner seg faults on Ctrl-D Date: Thu, 19 Jul 2001 06:23:27 +0300 From: Chad David <davidc@acns.ab.ca> Subject: bin/29074: banner seg faults on Ctrl-D Date: Wed, Jul 18, 2001 at 09:03:56PM -0600 > >Description: > When banner is run without any arguments it displays a > Message: prompt. If Ctrl-D is entered at that point the > program core dumps. > > >How-To-Repeat: > Run banner without any arguments and press Ctrl-D at the > Message: prompt. > > >Fix: > Zero the buffer prior to calling fgets() or check the return > value of fgets(), the later is probably more correct. Try the following patch. It seems to solve problems on my banner. Index: banner.c =================================================================== RCS file: /home/ncvs/src/usr.bin/banner/banner.c,v retrieving revision 1.11 diff -u -r1.11 banner.c --- banner.c 2001/05/28 03:49:23 1.11 +++ banner.c 2001/07/19 03:21:08 @@ -1075,7 +1075,8 @@ if ((message = malloc((size_t)MAXMSG)) == NULL) err(1, "malloc"); fprintf(stderr,"Message: "); - (void)fgets(message, MAXMSG, stdin); + if (fgets(message, MAXMSG, stdin) == NULL) + exit(0); nchars = strlen(message); message[nchars--] = '\0'; /* get rid of newline */ } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200107190330.f6J3U2M96823>