Skip to content

Commit bfef315

Browse files
committed
C++: Add additional SQL injection tests
1 parent 09dd000 commit bfef315

File tree

1 file changed

+27
-1
lines changed
  • cpp/ql/test/query-tests/Security/CWE/CWE-089/SqlTainted

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,30 @@ void ODBCTests(){
7575
gets(userInput);
7676
SQLPrepare(0, userInput, 100); // BAD
7777
SQLExecDirect(0, userInput, 100); // BAD
78-
}
78+
}
79+
80+
char* GetCommandLineA();
81+
char** CommandLineToArgvA(char *, int*);
82+
83+
void getCommandLine() {
84+
char *cmd = GetCommandLineA();
85+
int argc;
86+
char **argv = CommandLineToArgvA(cmd, &argc);
87+
88+
// a string from the user is injected directly into an SQL query.
89+
char query1[1000] = {0};
90+
snprintf(query1, 1000, "SELECT UID FROM USERS where name = \"%s\"", cmd);
91+
mysql_query(0, query1); // BAD
92+
93+
// a string from the user is injected directly into an SQL query.
94+
char query2[1000] = {0};
95+
snprintf(query2, 1000, "SELECT UID FROM USERS where name = \"%s\"", argv[1]);
96+
mysql_query(0, query2); // BAD
97+
}
98+
99+
int WinMain(void *hInstance, void *hPrevInstance, char *pCmdLine, int nCmdShow) {
100+
// a string from the user is injected directly into an SQL query.
101+
char query1[1000] = {0};
102+
snprintf(query1, 1000, "SELECT UID FROM USERS where name = \"%s\"", pCmdLine);
103+
mysql_query(0, query1); // BAD
104+
}

0 commit comments

Comments
 (0)