Skip to content

Commit c2b3177

Browse files
committed
C++: Fix for SQL query.
1 parent 32464a8 commit c2b3177

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cpp/ql/src/Security/CWE/CWE-089/SqlTainted.ql

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,21 @@ module SqlTaintedConfig implements DataFlow::ConfigSig {
5959
module SqlTainted = TaintTracking::Global<SqlTaintedConfig>;
6060

6161
from
62-
SqlLikeFunction runSql, Expr taintedArg, FlowSource taintSource, SqlTainted::PathNode sourceNode,
63-
SqlTainted::PathNode sinkNode, string callChain
62+
Expr taintedArg, FlowSource taintSource, SqlTainted::PathNode sourceNode,
63+
SqlTainted::PathNode sinkNode, string extraText
6464
where
65-
runSql.outermostWrapperFunctionCall(taintedArg, callChain) and
65+
(
66+
exists(SqlLikeFunction runSql, string callChain |
67+
runSql.outermostWrapperFunctionCall(taintedArg, callChain) and
68+
extraText = " and then passed to " + callChain
69+
)
70+
or
71+
sinkNode(sinkNode.getNode(), "sql-injection") and
72+
extraText = ""
73+
) and
6674
SqlTainted::flowPath(sourceNode, sinkNode) and
6775
taintedArg = asSinkExpr(sinkNode.getNode()) and
6876
taintSource = sourceNode.getNode()
6977
select taintedArg, sourceNode, sinkNode,
70-
"This argument to a SQL query function is derived from $@ and then passed to " + callChain + ".",
71-
taintSource, "user input (" + taintSource.getSourceType() + ")"
78+
"This argument to a SQL query function is derived from $@" + extraText + ".", taintSource,
79+
"user input (" + taintSource.getSourceType() + ")"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ subpaths
3636
| 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) |
3737
| 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) |
3838
| 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) |
39+
| 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) |
40+
| 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) |
3941
| 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) |

0 commit comments

Comments
 (0)