Skip to content

Commit 5388491

Browse files
committed
C++: Add more tests (which demonstrate a couple of bugs in the implementation).
1 parent 982de28 commit 5388491

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
| tests.cpp:324:3:324:9 | call to sprintf | This 'call to sprintf' operation requires 11 bytes but the destination is only 2 bytes. |
1010
| tests.cpp:327:2:327:8 | call to sprintf | This 'call to sprintf' operation requires 12 bytes but the destination is only 2 bytes. |
1111
| tests.cpp:329:3:329:9 | call to sprintf | This 'call to sprintf' operation requires 12 bytes but the destination is only 2 bytes. |
12+
| tests.cpp:345:2:345:8 | call to sprintf | This 'call to sprintf' operation requires 11 bytes but the destination is only 2 bytes. |

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,12 @@ void test6(unsigned unsigned_value, int value) {
337337
sprintf(buffer, "%d", 0); // GOOD
338338
sprintf(buffer, "%u", 5); // GOOD
339339
sprintf(buffer, "%d", 5); // GOOD
340+
341+
sprintf(buffer, "%d", -1); // BAD [NOT DETECTED]
342+
sprintf(buffer, "%d", 9); // GOOD
343+
sprintf(buffer, "%d", 10); // BAD [NOT DETECTED]
344+
345+
sprintf(buffer, "%u", -1); // BAD
346+
sprintf(buffer, "%u", 9); // GOOD
347+
sprintf(buffer, "%u", 10); // BAD [NOT DETECTED]
340348
}

0 commit comments

Comments
 (0)