Skip to content

Commit 01b204e

Browse files
committed
C++: Add a test case with a tainted integer.
1 parent 7a3f9c7 commit 01b204e

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
edges
2-
| test.c:14:20:14:23 | argv | test.c:19:18:19:23 | (const char *)... |
3-
| test.c:14:20:14:23 | argv | test.c:19:18:19:23 | (const char *)... |
4-
| test.c:14:20:14:23 | argv | test.c:19:18:19:23 | query1 |
5-
| test.c:14:20:14:23 | argv | test.c:19:18:19:23 | query1 |
2+
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | (const char *)... |
3+
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | (const char *)... |
4+
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 |
5+
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 |
6+
| test.c:16:25:16:28 | argv | test.c:33:18:33:23 | (const char *)... |
7+
| test.c:16:25:16:28 | argv | test.c:33:18:33:23 | (const char *)... |
8+
| test.c:16:25:16:28 | argv | test.c:33:18:33:23 | query3 |
9+
| test.c:16:25:16:28 | argv | test.c:33:18:33:23 | query3 |
610
nodes
7-
| test.c:14:20:14:23 | argv | semmle.label | argv |
8-
| test.c:14:20:14:23 | argv | semmle.label | argv |
9-
| test.c:19:18:19:23 | (const char *)... | semmle.label | (const char *)... |
10-
| test.c:19:18:19:23 | (const char *)... | semmle.label | (const char *)... |
11-
| test.c:19:18:19:23 | query1 | semmle.label | query1 |
11+
| test.c:15:20:15:23 | argv | semmle.label | argv |
12+
| test.c:15:20:15:23 | argv | semmle.label | argv |
13+
| test.c:16:25:16:28 | argv | semmle.label | argv |
14+
| test.c:16:25:16:28 | argv | semmle.label | argv |
15+
| test.c:21:18:21:23 | (const char *)... | semmle.label | (const char *)... |
16+
| test.c:21:18:21:23 | (const char *)... | semmle.label | (const char *)... |
17+
| test.c:21:18:21:23 | query1 | semmle.label | query1 |
18+
| test.c:33:18:33:23 | (const char *)... | semmle.label | (const char *)... |
19+
| test.c:33:18:33:23 | (const char *)... | semmle.label | (const char *)... |
20+
| test.c:33:18:33:23 | query3 | semmle.label | query3 |
1221
#select
13-
| test.c:19:18:19:23 | query1 | test.c:14:20:14:23 | argv | test.c:19:18:19:23 | query1 | This argument to a SQL query function is derived from $@ and then passed to mysql_query(sqlArg) | test.c:14:20:14:23 | argv | user input (argv) |
22+
| test.c:21:18:21:23 | query1 | test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 | This argument to a SQL query function is derived from $@ and then passed to mysql_query(sqlArg) | test.c:15:20:15:23 | argv | user input (argv) |
23+
| test.c:33:18:33:23 | query3 | test.c:16:25:16:28 | argv | test.c:33:18:33:23 | query3 | This argument to a SQL query function is derived from $@ and then passed to mysql_query(sqlArg) | test.c:16:25:16:28 | argv | user input (argv) |

cpp/ql/test/query-tests/Security/CWE/CWE-089/SqlTainted/test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ typedef unsigned long size_t;
77
int snprintf(char *s, size_t n, const char *format, ...);
88
void sanitizeString(char *stringOut, size_t len, const char *strIn);
99
int mysql_query(int arg1, const char *sqlArg);
10+
int atoi(const char *nptr);
1011

1112
///// Test code /////
1213

1314
int main(int argc, char** argv) {
1415
char *userName = argv[2];
16+
int userNumber = atoi(argv[3]);
1517

1618
// a string from the user is injected directly into an SQL query.
1719
char query1[1000] = {0};
@@ -24,4 +26,9 @@ int main(int argc, char** argv) {
2426
char query2[1000] = {0};
2527
snprintf(query2, 1000, "SELECT UID FROM USERS where name = \"%s\"", userNameSanitized);
2628
mysql_query(0, query2); // GOOD
29+
30+
// an integer from the user is injected into an SQL query.
31+
char query3[1000] = {0};
32+
snprintf(query3, 1000, "SELECT UID FROM USERS where number = \"%i\"", userNumber);
33+
mysql_query(0, query3); // BAD [FALSE POSITIVE]
2734
}

0 commit comments

Comments
 (0)