PDA

View Full Version : C: gets() function warning.



kapok
January 19th, 2009, 12:14 AM
whats dangerous about the gets() function?

jimi_hendrix
January 19th, 2009, 12:25 AM
buffer overflow...use fgets() instead

kapok
January 19th, 2009, 12:26 AM
fgets() works the same way?

jimi_hendrix
January 19th, 2009, 12:30 AM
myString = fgets(myString, sizeof(string), stdin);
/*takes a string, how many chars to read, and the file (in this case stdin for cli input) to read returns the value of the string you pass so i think what i have up there is redundent*/

module0000
January 19th, 2009, 01:29 AM
Can ram as many characters into gets() input as you want, eventually writing to memory you have no business writing to.