Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > What's wrong with gets()?

What's wrong with gets()?
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Apr 2, 2003, 04:13 PM
 
I'm running a cli app that gives me this warning:

warning: this program uses gets(), which is unsafe.


Can someone tell me what's wrong with gets()?

thanks,
kman
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Apr 2, 2003, 06:00 PM
 
[ mithras@jukebox ] man gets

... snipped ...

BUGS
Since it is usually impossible to ensure that the next input line is less
than some arbitrary length, and because overflowing the input buffer is
almost invariably a security violation, programs should NEVER use gets().
The gets() function exists purely to conform to ISO/IEC 9899:1990
(``ISO C89'').

So i guess it's hackable, only really worrisome if the program accepts input from the network, or strangers.
     
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Apr 2, 2003, 09:37 PM
 
Buffer overflow is the problem. gets() will keep writing into a buffer after the end of the buffer causing the potential for a buffer overflow - a frequent cause of security updates on programs. You should use fgets() which takes a length argument and will never read more characters than this length and therefore won't overflow.

Wesley
     
Dedicated MacNNer
Join Date: Sep 2002
Status: Offline
Reply With Quote
Apr 3, 2003, 12:41 PM
 
So i guess it's hackable, only really worrisome if the program accepts input from the network, or strangers
Well, there is such a thing as getting into good habits. gets() should never have got into the standard in the first place (it dates from two years after the Internet Worm). I find it amusing that it is still in the C99 standard (or was, last time I checked).
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:13 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2