Can someone briefly summarize the security issues in C? If you manage memory properly and take a conservative approach to handling input, where is the risk?
Like I said, I'm young and have only be programming in C for ~3 years.
Can someone briefly summarize the security issues in C? If you manage memory properly and take a conservative approach to handling input, where is the risk?
Like I said, I'm young and have only be programming in C for ~3 years.
If you're serious about writing safer C code, certainly check up the following two resources from Robert Seacord:
- SEI CERT C Coding Standard: https://wiki.sei.cmu.edu/confluence/display/c/SEI+CERT+C+Cod...
- Secure Coding in C and C++: https://resources.sei.cmu.edu/library/asset-view.cfm?assetid...
- Decays of arrays into pointers.
- Decays of enumeration into numeric types
- Default signess is implementation defined
- Implicit conversions
- Currently ISO C11 lists about 200 UB cases, C2X plans to list even more
- Strings are a pointer to somewhere in memory that you hope the caller actually terminated them.
- While the pre-processor seems basic, compared with real macros, you can still be very creative with it
- No way to validate security issues in binary libraries
The LLVM and PVS Studio blogs have quite a few examples of C gotchas.
That sounds like a benefit, not a downside. See, for instance, http://libcello.org/
Doing code fixes on a server code which was using clever tricks to convert between memory handles and the real memory addresses teached me that.
Not only does this survey some interesting C behaviors in practice but asks "Do you know of real code that relies on it?" and there's always a number of "yes" / "yes, but it shouldn't" and also "no, that would be crazy" answers to each :D