File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-242/semmle/tests Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 22| tests.cpp:259:2:259:8 | call to sprintf | This conversion may yield a string of length 17, which exceeds the allocated buffer size of 10 |
33| tests.cpp:272:2:272:8 | call to sprintf | This conversion may yield a string of length 9, which exceeds the allocated buffer size of 8 |
44| tests.cpp:273:2:273:8 | call to sprintf | This conversion may yield a string of length 9, which exceeds the allocated buffer size of 8 |
5+ | tests.cpp:287:2:287:8 | call to sprintf | This conversion may yield a string of length 318, which exceeds the allocated buffer size of 64 |
Original file line number Diff line number Diff line change @@ -272,3 +272,20 @@ void test4()
272272 sprintf (buffer8, " 12345678" ); // BAD: buffer overflow
273273 sprintf (buffer8_ptr, " 12345678" ); // BAD: buffer overflow
274274}
275+
276+ typedef void *va_list;
277+ int vsprintf (char *s, const char *format, va_list arg);
278+
279+ void test5 (va_list args, float f)
280+ {
281+ char buffer10[10 ], buffer64[64 ];
282+ char *buffer4 = new char [4 * sizeof (char )];
283+
284+ vsprintf (buffer10, " 123456789" , args); // GOOD
285+ vsprintf (buffer10, " 1234567890" , args); // BAD: buffer overflow [NOT DETECTED]
286+
287+ sprintf (buffer64, " %f" , f); // BAD: potential buffer overflow
288+
289+ vsprintf (buffer4, " 123" , args); // GOOD
290+ vsprintf (buffer4, " 1234" , args); // BAD: buffer overflow [NOT DETECTED]
291+ }
You can’t perform that action at this time.
0 commit comments