LinuxQuestions.org
Visit Jeremy's Blog.
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 10-02-2004, 12:32 PM   #1
mullog
Member
 
Registered: May 2004
Posts: 61

Rep: Reputation: 15
Is fgets functions secure?


Hi,

I read that fgets isn't secure, but not why. Could someone please explain me why?
 
Old 10-02-2004, 12:52 PM   #2
mirradric
Member
 
Registered: May 2004
Location: Singapore
Distribution: Debian woody and debian sarge
Posts: 188

Rep: Reputation: 31
from what I know fgets is more secure than gets since the fgets requires you to specify the size of the buffer.

I guess it could be insecure because the programmer may specify the wrong size. Not sure about this one so i'll be watching this thread.
 
Old 10-02-2004, 01:22 PM   #3
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
fgets() is secure as long as (mentioned)the length calculation is correct. However, there is sometimes confusion as to how it deals with input. If there is not a newline in the first 'len' bytes of the file handle, the buffer will not contain a newline, but it will _always_ be NULL terminated.
 
  


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
php fgets really slow pasholy2001 Programming 0 04-22-2005 02:17 AM
reading in string with fgets bostonbanana Programming 4 12-12-2004 02:10 PM
fgets() problems in C AMMullan Programming 4 03-12-2004 04:39 AM
fgets h/w Programming 23 12-21-2003 06:20 PM
fgets vs gets cxel91a Programming 2 12-01-2003 12:36 PM

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

All times are GMT -5. The time now is 06:07 PM.

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