I want to know the disadvantages of scanf()
.
In many sites, I have read that using scanf
might cause buffer overflows. What is the reason f
Yes, you are right. There is a major security flaw in scanf
family(scanf
,sscanf
, fscanf
..etc) esp when reading a string, because they don't take the length of the buffer (into which they are reading) into account.
Example:
char buf[3];
sscanf("abcdef","%s",buf);
clearly the the buffer buf
can hold MAX 3
char. But the sscanf
will try to put "abcdef"
into it causing buffer overflow.