home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / linux / 22398 < prev    next >
Encoding:
Internet Message Format  |  1993-01-01  |  2.2 KB

  1. Path: sparky!uunet!think.com!enterpoop.mit.edu!cambridge-news.cygnus.com!athena.mit.edu!eichin
  2. From: eichin@athena.mit.edu (Mark Eichin)
  3. Newsgroups: comp.os.linux
  4. Subject: Re: "the `gets' function is unreliable and should not be used"??!!!
  5. Date: 2 Jan 1993 00:22:44 GMT
  6. Organization: Massachusetts Institute of Technology
  7. Lines: 33
  8. Message-ID: <EICHIN.93Jan1192127@tweedledumber.mit.edu>
  9. References: <C058sJ.Fuu@news.cso.uiuc.edu>
  10. NNTP-Posting-Host: tweedledumber.cygnus.com
  11. In-reply-to: dld54032@uxa.cso.uiuc.edu's message of Thu, 31 Dec 1992 21:53:06 GMT
  12.  
  13. >> From: dld54032@uxa.cso.uiuc.edu (Dave Dribin)
  14. >> really unreliable.  I would think that all the standard ASNI functions would
  15. >> be reliable!  Thanx in andvance, and happy new year...
  16.     The ANSI C standard (or at least, X3.159-1989, I believe there
  17. was a 1990 update that I don't have yet) makes no mention of the
  18. problem; the "Rationale" only mentions that fgets subsumes gets
  19. because gets has no way to limit the size of the input buffer. The
  20. documentation I wrote for a free C library documents gets in a much
  21. stronger way:
  22.  
  23.     This is a <[dangerous]> function, as it has no way of checking
  24.     the amount of space available in <[buf]>. One of the attacks
  25.     used by the Internet Virus of 1988 used this to overrun a
  26.     buffer allocated on the stack of the finger daemon and
  27.     overwrite the return address, causing the daemon to execute
  28.     code downloaded into it over the connection.
  29.  
  30. If you look up some of the papers written about the Morris Virus,
  31. you'll find some of them mention that BSD only had gets for backwards
  32. compatibility, and that fgets had been introduced around ***1978***
  33. and there was no reason for any code written since then to use gets.
  34. You'll also find vivid detail of how sloppy code (like gets) can make
  35. it possible for someone to break into your system.
  36.     I think it was a mistake for ANSI to standardize that
  37. interface (especially without at least justifying it in the rationale)
  38. but they were, after all, only supposed to codify existing practice,
  39. even if existing practice was incorrect.
  40.  
  41.                 _Mark_ <eichin@athena.mit.edu>
  42.                 MIT Student Information Processing Board
  43.                 Cygnus Support <eichin@cygnus.com>
  44. ps. Feel free to forward this to whoever teaches the class that you
  45. were writing that code for :-)
  46.