From owner-freebsd-bugs Wed Jul 18 20:30: 7 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 3DB2437B403 for ; Wed, 18 Jul 2001 20:30:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f6J3U2M96823; Wed, 18 Jul 2001 20:30:02 -0700 (PDT) (envelope-from gnats) Date: Wed, 18 Jul 2001 20:30:02 -0700 (PDT) Message-Id: <200107190330.f6J3U2M96823@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Giorgos Keramidas Subject: Re: bin/29074: banner seg faults on Ctrl-D Reply-To: Giorgos Keramidas Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/29074; it has been noted by GNATS. From: Giorgos Keramidas To: Chad David 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 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