Skip to content

Commit 1cf4449

Browse files
committed
CPP: Test for NonConstantFormat with multiple definitons.
1 parent 144cda7 commit 1cf4449

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

cpp/ql/test/query-tests/Likely Bugs/Format/NonConstantFormat/NonConstantFormat.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
| NonConstantFormat.c:30:10:30:16 | access to array | The format string argument to printf should be constant to prevent security issues and other potential errors. |
22
| NonConstantFormat.c:41:9:41:27 | call to any_random_function | The format string argument to printf should be constant to prevent security issues and other potential errors. |
3+
| a.c:15:37:15:45 | call to getString | The format string argument to myMultiplyDefinedPrintf should be constant to prevent security issues and other potential errors. |
4+
| a.c:16:27:16:35 | call to getString | The format string argument to myMultiplyDefinedPrintf should be constant to prevent security issues and other potential errors. |
5+
| a.c:17:38:17:46 | call to getString | The format string argument to myMultiplyDefinedPrintf2 should be constant to prevent security issues and other potential errors. |
6+
| a.c:18:28:18:36 | call to getString | The format string argument to myMultiplyDefinedPrintf2 should be constant to prevent security issues and other potential errors. |
7+
| b.c:12:37:12:45 | call to getString | The format string argument to myMultiplyDefinedPrintf should be constant to prevent security issues and other potential errors. |
8+
| b.c:13:27:13:35 | call to getString | The format string argument to myMultiplyDefinedPrintf should be constant to prevent security issues and other potential errors. |
9+
| b.c:14:38:14:46 | call to getString | The format string argument to myMultiplyDefinedPrintf2 should be constant to prevent security issues and other potential errors. |
10+
| b.c:15:28:15:36 | call to getString | The format string argument to myMultiplyDefinedPrintf2 should be constant to prevent security issues and other potential errors. |
311
| nested.cpp:21:23:21:26 | fmt0 | The format string argument to snprintf should be constant to prevent security issues and other potential errors. |
412
| nested.cpp:79:32:79:38 | call to get_fmt | The format string argument to diagnostic should be constant to prevent security issues and other potential errors. |
513
| nested.cpp:87:18:87:20 | fmt | The format string argument to diagnostic should be constant to prevent security issues and other potential errors. |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
__attribute__((format(printf, 1, 3)))
3+
void myMultiplyDefinedPrintf(const char *format, const char *extraArg, ...)
4+
{
5+
// ...
6+
}
7+
8+
__attribute__((format(printf, 1, 3)))
9+
void myMultiplyDefinedPrintf2(const char *format, const char *extraArg, ...);
10+
11+
char *getString();
12+
13+
void test_custom_printf1()
14+
{
15+
myMultiplyDefinedPrintf("string", getString()); // GOOD [FALSE POSITIVE]
16+
myMultiplyDefinedPrintf(getString(), "string"); // BAD
17+
myMultiplyDefinedPrintf2("string", getString()); // GOOD (we can't tell which definition is correct so we have to assume this is OK) [FALSE POSITIVE]
18+
myMultiplyDefinedPrintf2(getString(), "string"); // GOOD (we can't tell which definition is correct so we have to assume this is OK) [FALSE POSITIVE]
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
__attribute__((format(printf, 2, 3)))
3+
void myMultiplyDefinedPrintf(const char *extraArg, const char *format, ...); // this declaration does not match the definition
4+
5+
__attribute__((format(printf, 2, 3)))
6+
void myMultiplyDefinedPrintf2(const char *extraArg, const char *format, ...);
7+
8+
char *getString();
9+
10+
void test_custom_printf2(char *string)
11+
{
12+
myMultiplyDefinedPrintf("string", getString()); // GOOD [FALSE POSITIVE]
13+
myMultiplyDefinedPrintf(getString(), "string"); // BAD
14+
myMultiplyDefinedPrintf2("string", getString()); // GOOD (we can't tell which definition is correct so we have to assume this is OK) [FALSE POSITIVE]
15+
myMultiplyDefinedPrintf2(getString(), "string"); // GOOD (we can't tell which definition is correct so we have to assume this is OK) [FALSE POSITIVE]
16+
}

0 commit comments

Comments
 (0)