Files
codeql/cpp/ql/src/Likely Bugs/Memory Management/PotentialBufferOverflow.cpp
2018-09-23 16:23:52 -07:00

13 lines
381 B
C++

void f(char* s, float f) {
char buf[30];
//wrong: gets has no limit to the length of data it puts in the buffer
gets(buf);
//wrong: sprintf does not limit the length of the string put into buf
sprintf(buf, "This is a string: %s", s);
//wrong: %f can expand to a very long string in extreme cases, easily overrunning this buffer
sprintf(buf, "This is a float: %f", f);
}