Why is it usually a bad idea to use gets()? Suggest a workaround.



Why is it usually a bad idea to use gets()? Suggest a workaround...

Answer / hrpynux@gmail.com

The function gets() reads characters from the stdin and stores them at the provided input buffer. However, gets() will keep reading until it encounters a newline character. Unless the buffer is large enough, or the length of the line being read is known ahead of time, gets() can potentially overflow the input buffer and start overwriting memory it is not supposed to, wreaking havoc or opening security vulnerabilities.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Is swift based on c?

0 Answers  


get any number as input except 1 and the output will be 1.without using operators,expressions,array,structure.don't print 1 in printf statement

3 Answers  


Why is main function so important?

0 Answers  


What are keywords in c with examples?

0 Answers  


Why do u use # before include in a C Progam?

9 Answers   IBM,






Which of the following about automatic variables within a function is correct ? a.its type must be declared before using the variable b.they are local c.they are not initialised to zero d.they are global.

6 Answers   FCI, TCS,


union { char ch[10]; short s; }test; test.s = 0xabcd; main() { printf("%d",ch[10]); }

3 Answers  


How to implement a packet in C

0 Answers   Aricent,


main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

5 Answers   Vector, Vector Solutions,


int zap(int n) { if(n<=1)then zap=1; else zap=zap(n-3)+zap(n-1); } then the call zap(6) gives the values of zap [a] 8 [b] 9 [c] 6 [d] 12 [e] 15

10 Answers   Wipro,


what is the difference between getch() and getchar()?

10 Answers   Huawei, Infosys,


what does keyword ‘extern’ mean in a function declaration?

1 Answers   Emerson,


Categories