Skip to content

Commit 947e027

Browse files
committed
Adding sql injection test for ODBC.
1 parent f404d7a commit 947e027

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ edges
44
| test.c:35:16:35:23 | userName indirection | test.c:40:25:40:32 | username indirection |
55
| test.c:38:7:38:20 | globalUsername indirection | test.c:51:18:51:23 | query1 indirection |
66
| test.c:40:25:40:32 | username indirection | test.c:38:7:38:20 | globalUsername indirection |
7+
| test.c:75:8:75:16 | gets output argument | test.c:76:17:76:25 | userInput indirection |
8+
| test.c:75:8:75:16 | gets output argument | test.c:77:20:77:28 | userInput indirection |
79
| test.cpp:39:27:39:30 | argv indirection | test.cpp:43:27:43:33 | access to array indirection |
810
nodes
911
| test.c:14:27:14:30 | argv indirection | semmle.label | argv indirection |
@@ -12,10 +14,15 @@ nodes
1214
| test.c:38:7:38:20 | globalUsername indirection | semmle.label | globalUsername indirection |
1315
| test.c:40:25:40:32 | username indirection | semmle.label | username indirection |
1416
| test.c:51:18:51:23 | query1 indirection | semmle.label | query1 indirection |
17+
| test.c:75:8:75:16 | gets output argument | semmle.label | gets output argument |
18+
| test.c:76:17:76:25 | userInput indirection | semmle.label | userInput indirection |
19+
| test.c:77:20:77:28 | userInput indirection | semmle.label | userInput indirection |
1520
| test.cpp:39:27:39:30 | argv indirection | semmle.label | argv indirection |
1621
| test.cpp:43:27:43:33 | access to array indirection | semmle.label | access to array indirection |
1722
subpaths
1823
#select
1924
| test.c:21:18:21:23 | query1 | test.c:14:27:14:30 | argv indirection | test.c:21:18:21:23 | query1 indirection | This argument to a SQL query function is derived from $@ and then passed to mysql_query(sqlArg). | test.c:14:27:14:30 | argv indirection | user input (a command-line argument) |
2025
| test.c:51:18:51:23 | query1 | test.c:14:27:14:30 | argv indirection | test.c:51:18:51:23 | query1 indirection | This argument to a SQL query function is derived from $@ and then passed to mysql_query(sqlArg). | test.c:14:27:14:30 | argv indirection | user input (a command-line argument) |
26+
| test.c:76:17:76:25 | userInput | test.c:75:8:75:16 | gets output argument | test.c:76:17:76:25 | userInput indirection | This argument to a SQL query function is derived from $@ and then passed to SQLPrepare(StatementText). | test.c:75:8:75:16 | gets output argument | user input (string read by gets) |
27+
| test.c:77:20:77:28 | userInput | test.c:75:8:75:16 | gets output argument | test.c:77:20:77:28 | userInput indirection | This argument to a SQL query function is derived from $@ and then passed to SQLExecDirect(StatementText). | test.c:75:8:75:16 | gets output argument | user input (string read by gets) |
2128
| test.cpp:43:27:43:33 | access to array | test.cpp:39:27:39:30 | argv indirection | test.cpp:43:27:43:33 | access to array indirection | This argument to a SQL query function is derived from $@ and then passed to pqxx::work::exec1((unnamed parameter 0)). | test.cpp:39:27:39:30 | argv indirection | user input (a command-line argument) |

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,29 @@ void badFunc() {
5050
snprintf(query1, 1000, "SELECT UID FROM USERS where name = \"%s\"", userName);
5151
mysql_query(0, query1); // BAD
5252
}
53+
54+
//ODBC Library Rountines
55+
typedef unsigned char SQLCHAR;
56+
typedef long int SQLINTEGER;
57+
typedef int SQLRETURN;
58+
typedef void* SQLHSTMT;
59+
60+
char* gets(char *str);
61+
62+
63+
SQLRETURN SQLPrepare(
64+
SQLHSTMT StatementHandle,
65+
SQLCHAR * StatementText,
66+
SQLINTEGER TextLength);
67+
68+
SQLRETURN SQLExecDirect(
69+
SQLHSTMT StatementHandle,
70+
SQLCHAR * StatementText,
71+
SQLINTEGER TextLength);
72+
73+
void ODBCTests(){
74+
char userInput[100];
75+
gets(userInput);
76+
SQLPrepare(0, userInput, 100); // BAD
77+
SQLExecDirect(0, userInput, 100); // BAD
78+
}

0 commit comments

Comments
 (0)