Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Dec 1995 13:22:53 +0800 (WST)
From:      Peter Wemm <peter@jhome.DIALix.COM>
To:        Bruce Evans <bde@zeta.org.au>
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
Message-ID:  <Pine.BSF.3.91.951228130224.13067H-100000@jhome.DIALix.COM>
In-Reply-To: <199512280431.PAA13912@godzilla.zeta.org.au>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.951228130224.13067H-100000>