Almost all the code I see with c tags in questions uses gets()
or scanf()
. It's okay that new c coders get their input from stdin
that way. But when someone fixes his code, in my opinion, he should change their gets()
and scanf()
calls to fgets()
with sscanf()
, or any other secure combination.
You may think that was not the original problem, so why should we change it? Well, their habit of using insecure coding will not be changed. And, in the future, all of a sudden, you will get hacked because one of these guys will someday write your router firmware or other system software.
You may say that when they are competent enough to write firmware, they will have also learned to avoid this. It's true to some extent. But I worked on a firmware project in my university years, and I had no idea about security bugs. I wrote my part. It shipped with a GPS tracker product. My company didn't have any code review practice. So no one noticed. My managers were incompetent enough to accept my svn commits happily.
Looking back, those bugs, which my code introduced, give me a quiet nightmare. I personally avoid the hardware products of the company I worked with.
The bottom line is this: if they were removed from stdlib
, it would be better. But that's not happening because of existing code bases.
So my opinion is to fix code with security issues. Most of these fixes are trivial enough. Does anyone think the same thing?
scanf()
andgets()
. It is a good idea, though, to edit canonical answer (answer only) on questions with high views to warn user about the security issue with using those functions.printf(userstring);
,strNthing
.gets()
orscanf()
." Almost all, really? I seescanf
fairly often, but I rarely seegets
.