Skip to content

Commit 7194121

Browse files
committed
CPP: Expand the test cases covering PotentialBufferOverflow.ql.
1 parent 999e0c8 commit 7194121

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
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 |

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)