From owner-cvs-usrbin Wed Dec 27 21:23:29 1995 Return-Path: owner-cvs-usrbin Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id VAA14330 for cvs-usrbin-outgoing; Wed, 27 Dec 1995 21:23:29 -0800 (PST) Received: from jhome.DIALix.COM (root@jhome.DIALix.COM [192.203.228.69]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id VAA14313 Wed, 27 Dec 1995 21:23:17 -0800 (PST) Received: (from peter@localhost) by jhome.DIALix.COM (8.7.3/8.7.3) id NAA13964; Thu, 28 Dec 1995 13:22:53 +0800 (WST) Date: Thu, 28 Dec 1995 13:22:53 +0800 (WST) From: Peter Wemm To: Bruce Evans cc: CVS-committers@freefall.freebsd.org, cvs-usrbin@freefall.freebsd.org, joerg@freefall.freebsd.org Subject: Re: cvs commit: src/usr.bin/tftp main.c In-Reply-To: <199512280431.PAA13912@godzilla.zeta.org.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-cvs-usrbin@FreeBSD.ORG Precedence: bulk On Thu, 28 Dec 1995, Bruce Evans wrote: > > Modified: usr.bin/tftp main.c > > Log: > > Kill the (hopefully) last occurance of gets(3) in the base source tree. > > > > Revision Changes Path > > 1.3 +11 -6 src/usr.bin/tftp/main.c > > Now we can start fixing the fixes :-(. The one in sail/pl_main.c leaves > \n in the captain's name, and almost all of them don't read to the end > of the line for long lines, so junk may be left for the next read. I > would prefer a core dump. > > Bruce Perhaps the safest "fix" may be to shove a simple replacement for gets() into libc or libutil with a similar interface that we can use to take care of this sort of thing. We can edit our sources to change gets(line); to __ngets(line, sizeof(line)); stub take care of the hard work. Naturally, it's not portable but heck, our sources are for FreeBSD, not PortableBSD.. :-) Perhaps something like this for starters.. char * __ngets(buf, len) char *buf; size_t len; { char *s; size_t l; s = fgetln(stdin, &l); if (s == NULL || l == 0) { return NULL; } else { if (s[l-1] == '\n') --l; if (l > (len - 1)) l = len - 1; memcpy(buf, s, l); buf[l] = '\0'; return buf; } } Dont shoot! :-) It's just a thought... :-) (or perhaps put this in as a static function in the programs that wanted to call gets() in the first place and get them to use this instead...) Cheers, -Peter