mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
C++: Pretty print MaD ids in test output
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
#select
|
||||
| test.c:21:18:21:23 | query1 | test.c:14:27:14:30 | **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:14:27:14:30 | **argv | user input (a command-line argument) |
|
||||
| test.c:51:18:51:23 | query1 | test.c:14:27:14:30 | **argv | test.c:51:18:51:23 | *query1 | This argument to a SQL query function is derived from $@ and then passed to mysql_query(sqlArg). | test.c:14:27:14:30 | **argv | user input (a command-line argument) |
|
||||
| test.c:76:17:76:25 | userInput | test.c:75:8:75:16 | gets output argument | test.c:76:17:76:25 | *userInput | 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) |
|
||||
| test.c:77:20:77:28 | userInput | test.c:75:8:75:16 | gets output argument | test.c:77:20:77:28 | *userInput | 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) |
|
||||
| test.c:106:24:106:29 | query1 | test.c:101:8:101:16 | gets output argument | test.c:106:24:106:29 | *query1 | This argument to a SQL query function is derived from $@. | test.c:101:8:101:16 | gets output argument | user input (string read by gets) |
|
||||
| test.c:107:28:107:33 | query1 | test.c:101:8:101:16 | gets output argument | test.c:107:28:107:33 | *query1 | This argument to a SQL query function is derived from $@. | test.c:101:8:101:16 | gets output argument | user input (string read by gets) |
|
||||
| test.cpp:43:27:43:33 | access to array | test.cpp:39:27:39:30 | **argv | test.cpp:43:27:43:33 | *access to array | 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 | user input (a command-line argument) |
|
||||
edges
|
||||
| test.c:14:27:14:30 | **argv | test.c:15:20:15:26 | *access to array | provenance | |
|
||||
| test.c:15:20:15:26 | *access to array | test.c:21:18:21:23 | *query1 | provenance | TaintFunction |
|
||||
@@ -9,9 +17,12 @@ edges
|
||||
| test.c:48:20:48:33 | *globalUsername | test.c:51:18:51:23 | *query1 | provenance | TaintFunction |
|
||||
| test.c:75:8:75:16 | gets output argument | test.c:76:17:76:25 | *userInput | provenance | |
|
||||
| test.c:75:8:75:16 | gets output argument | test.c:77:20:77:28 | *userInput | provenance | |
|
||||
| test.c:101:8:101:16 | gets output argument | test.c:106:24:106:29 | *query1 | provenance | TaintFunction Sink:MaD:325 |
|
||||
| test.c:101:8:101:16 | gets output argument | test.c:107:28:107:33 | *query1 | provenance | TaintFunction Sink:MaD:326 |
|
||||
| test.c:101:8:101:16 | gets output argument | test.c:106:24:106:29 | *query1 | provenance | TaintFunction Sink:MaD:2 |
|
||||
| test.c:101:8:101:16 | gets output argument | test.c:107:28:107:33 | *query1 | provenance | TaintFunction Sink:MaD:1 |
|
||||
| test.cpp:39:27:39:30 | **argv | test.cpp:43:27:43:33 | *access to array | provenance | |
|
||||
models
|
||||
| 1 | Sink: ; ; false; OCIStmtPrepare2; ; ; Argument[*3]; sql-injection; manual |
|
||||
| 2 | Sink: ; ; false; OCIStmtPrepare; ; ; Argument[*2]; sql-injection; manual |
|
||||
nodes
|
||||
| test.c:14:27:14:30 | **argv | semmle.label | **argv |
|
||||
| test.c:15:20:15:26 | *access to array | semmle.label | *access to array |
|
||||
@@ -31,11 +42,3 @@ nodes
|
||||
| test.cpp:39:27:39:30 | **argv | semmle.label | **argv |
|
||||
| test.cpp:43:27:43:33 | *access to array | semmle.label | *access to array |
|
||||
subpaths
|
||||
#select
|
||||
| test.c:21:18:21:23 | query1 | test.c:14:27:14:30 | **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:14:27:14:30 | **argv | user input (a command-line argument) |
|
||||
| test.c:51:18:51:23 | query1 | test.c:14:27:14:30 | **argv | test.c:51:18:51:23 | *query1 | This argument to a SQL query function is derived from $@ and then passed to mysql_query(sqlArg). | test.c:14:27:14:30 | **argv | user input (a command-line argument) |
|
||||
| test.c:76:17:76:25 | userInput | test.c:75:8:75:16 | gets output argument | test.c:76:17:76:25 | *userInput | 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) |
|
||||
| test.c:77:20:77:28 | userInput | test.c:75:8:75:16 | gets output argument | test.c:77:20:77:28 | *userInput | 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) |
|
||||
| test.c:106:24:106:29 | query1 | test.c:101:8:101:16 | gets output argument | test.c:106:24:106:29 | *query1 | This argument to a SQL query function is derived from $@. | test.c:101:8:101:16 | gets output argument | user input (string read by gets) |
|
||||
| test.c:107:28:107:33 | query1 | test.c:101:8:101:16 | gets output argument | test.c:107:28:107:33 | *query1 | This argument to a SQL query function is derived from $@. | test.c:101:8:101:16 | gets output argument | user input (string read by gets) |
|
||||
| test.cpp:43:27:43:33 | access to array | test.cpp:39:27:39:30 | **argv | test.cpp:43:27:43:33 | *access to array | 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 | user input (a command-line argument) |
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
Security/CWE/CWE-089/SqlTainted.ql
|
||||
query: Security/CWE/CWE-089/SqlTainted.ql
|
||||
postprocess:
|
||||
- utils/test/PrettyPrintModels.ql
|
||||
- utils/test/InlineExpectationsTestQuery.ql
|
||||
|
||||
@@ -11,14 +11,14 @@ int atoi(const char *nptr);
|
||||
void exit(int i);
|
||||
///// Test code /////
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main(int argc, char** argv) { // $ Source
|
||||
char *userName = argv[2];
|
||||
int userNumber = atoi(argv[3]);
|
||||
|
||||
// a string from the user is injected directly into an SQL query.
|
||||
char query1[1000] = {0};
|
||||
snprintf(query1, 1000, "SELECT UID FROM USERS where name = \"%s\"", userName);
|
||||
mysql_query(0, query1); // BAD
|
||||
mysql_query(0, query1); // $ Alert
|
||||
|
||||
// the user string is encoded by a library routine.
|
||||
char userNameSanitized[1000] = {0};
|
||||
@@ -48,7 +48,7 @@ void badFunc() {
|
||||
char *userName = globalUsername;
|
||||
char query1[1000] = {0};
|
||||
snprintf(query1, 1000, "SELECT UID FROM USERS where name = \"%s\"", userName);
|
||||
mysql_query(0, query1); // BAD
|
||||
mysql_query(0, query1); // $ Alert
|
||||
}
|
||||
|
||||
//ODBC Library Rountines
|
||||
@@ -72,9 +72,9 @@ SQLRETURN SQLPrepare(
|
||||
|
||||
void ODBCTests(){
|
||||
char userInput[100];
|
||||
gets(userInput);
|
||||
SQLPrepare(0, userInput, 100); // BAD
|
||||
SQLExecDirect(0, userInput, 100); // BAD
|
||||
gets(userInput); // $ Source
|
||||
SQLPrepare(0, userInput, 100); // $ Alert
|
||||
SQLExecDirect(0, userInput, 100); // $ Alert
|
||||
}
|
||||
|
||||
// Oracle Call Interface (OCI) Routines
|
||||
@@ -98,13 +98,13 @@ int OCIStmtPrepare2(
|
||||
|
||||
void OCITests(){
|
||||
char userInput[100];
|
||||
gets(userInput);
|
||||
gets(userInput); // $ Source
|
||||
|
||||
// a string from the user is injected directly into an SQL query.
|
||||
char query1[1000] = {0};
|
||||
snprintf(query1, 1000, "SELECT UID FROM USERS where name = \"%s\"", userInput);
|
||||
OCIStmtPrepare(0, 0, query1, 0, 0, 0); // BAD
|
||||
OCIStmtPrepare2(0, 0, 0, query1, 0, 0, 0, 0, 0); // BAD
|
||||
OCIStmtPrepare(0, 0, query1, 0, 0, 0); // $ Alert
|
||||
OCIStmtPrepare2(0, 0, 0, query1, 0, 0, 0, 0, 0); // $ Alert
|
||||
|
||||
// an integer from the user is injected into an SQL query.
|
||||
int userNumber = atoi(userInput);
|
||||
|
||||
@@ -36,11 +36,11 @@ namespace pqxx {
|
||||
};
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main(int argc, char** argv) { // $ Source
|
||||
pqxx::connection c;
|
||||
pqxx::work w(c);
|
||||
|
||||
pqxx::row r = w.exec1(argv[1]); // BAD
|
||||
pqxx::row r = w.exec1(argv[1]); // $ Alert
|
||||
|
||||
pqxx::result r2 = w.exec(w.quote(argv[1])); // GOOD
|
||||
|
||||
|
||||
Reference in New Issue
Block a user