Skip to content

Commit d711c22

Browse files
committed
C++: Add testcase demonstrating lost query results
1 parent 7dd2677 commit d711c22

File tree

1 file changed

+19
-0
lines changed
  • cpp/ql/test/query-tests/Security/CWE/CWE-242/semmle/tests

1 file changed

+19
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-242/semmle/tests/tests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,22 @@ void test5(va_list args, float f)
289289
vsprintf(buffer4, "123", args); // GOOD
290290
vsprintf(buffer4, "1234", args); // BAD: buffer overflow [NOT DETECTED]
291291
}
292+
293+
namespace custom_sprintf_impl {
294+
int sprintf(char *buf, const char *format, ...)
295+
{
296+
__builtin_va_list args;
297+
int i;
298+
299+
__builtin_va_start(args, format);
300+
i = vsprintf(buf, format, args);
301+
__builtin_va_end(args);
302+
return i;
303+
}
304+
305+
void regression_test1()
306+
{
307+
char buffer8[8];
308+
sprintf(buffer8, "12345678"); // BAD: potential buffer overflow [NOT DETECTED]
309+
}
310+
}

0 commit comments

Comments
 (0)