LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-12-2005, 10:42 PM   #1
skie_knite007
Member
 
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Rep: Reputation: 15
Why gets() is having security problems????


I ve received warnings during compiling,,saying the usage of gets() is dangerous....Why is it so?
 
Old 12-12-2005, 10:56 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Read the man page for the function. On my system:
Quote:
char *gets(char *s);

...

gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with '\0'. No check for buffer overrun is performed (see BUGS below).

...

BUGS
Never use gets(). Because it is impossible to tell without knowing the data in advance how man characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.
gets() does not allocate a buffer for you. So you have to allocate memory for it yourself. No matter how much space you allocate, a string can be entered to exceed that space. By doing so, an unscrupulous individual can overwrite contents of memory by giving a longer-than-expected input string. If that input string is long enough, it can overwrite the program's instructions stored in memory, replacing them with code the user wants to execute. At the very least, the string could be used to alter data in memory on the system, and that might cause the program to behave unexpectedly.
 
  


Reply



Posting 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems Configuring Security via Mandrake Control Center vous Mandriva 5 03-17-2005 06:20 AM
Security Update Problems Rick485 Slackware 1 06-09-2004 04:59 PM
security level problems tscoker79 Linux - Software 1 04-06-2004 10:40 PM
Security problems with email Sarcha Linux - Security 4 02-05-2004 11:47 AM
wine security problems hulkt Linux - Security 3 11-23-2003 09:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration