Skip to content

Commit bb1712b

Browse files
committed
Merge branch 'main' into reuse-even-more-nodes
2 parents ef9d342 + 9957e26 commit bb1712b

File tree

745 files changed

+49819
-33555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

745 files changed

+49819
-33555
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Only the 2 level indirection of `argv` (corresponding to `**argv`) is consided for `FlowSource`.

cpp/ql/lib/semmle/code/cpp/security/FlowSources.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private class ArgvSource extends LocalFlowSource {
5353
exists(Function main, Parameter argv |
5454
main.hasGlobalName("main") and
5555
main.getParameter(1) = argv and
56-
this.asParameter(_) = argv
56+
this.asParameter(2) = argv
5757
)
5858
}
5959

cpp/ql/src/Likely Bugs/Format/NonConstantFormat.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ predicate isNonConst(DataFlow::Node node, boolean isIndirect) {
105105
or
106106
e instanceof NewArrayExpr
107107
or
108-
e instanceof AssignExpr
109-
or
110108
exists(Variable v | v = e.(VariableAccess).getTarget() |
111109
v.getType().(ArrayType).getBaseType() instanceof CharType and
112110
exists(AssignExpr ae |

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,55 @@
1414

1515
import cpp
1616
import semmle.code.cpp.security.Security
17+
import semmle.code.cpp.security.FlowSources
1718
import semmle.code.cpp.security.FunctionWithWrappers
18-
import semmle.code.cpp.ir.dataflow.internal.DefaultTaintTrackingImpl
19-
import TaintedWithPath
19+
import semmle.code.cpp.ir.IR
20+
import semmle.code.cpp.ir.dataflow.TaintTracking
21+
import SqlTainted::PathGraph
2022

2123
class SqlLikeFunction extends FunctionWithWrappers {
2224
SqlLikeFunction() { sqlArgument(this.getName(), _) }
2325

2426
override predicate interestingArg(int arg) { sqlArgument(this.getName(), arg) }
2527
}
2628

27-
class Configuration extends TaintTrackingConfiguration {
28-
override predicate isSink(Element tainted) {
29-
exists(SqlLikeFunction runSql | runSql.outermostWrapperFunctionCall(tainted, _))
29+
Expr asSinkExpr(DataFlow::Node node) {
30+
result = node.asIndirectArgument()
31+
or
32+
// We want the conversion so we only get one node for the expression
33+
result = node.asConvertedExpr()
34+
}
35+
36+
module SqlTaintedConfig implements DataFlow::ConfigSig {
37+
predicate isSource(DataFlow::Node node) { node instanceof FlowSource }
38+
39+
predicate isSink(DataFlow::Node node) {
40+
exists(SqlLikeFunction runSql | runSql.outermostWrapperFunctionCall(asSinkExpr(node), _))
3041
}
3142

32-
override predicate isBarrier(Expr e) {
33-
super.isBarrier(e)
34-
or
35-
e.getUnspecifiedType() instanceof IntegralType
36-
or
43+
predicate isBarrier(DataFlow::Node node) {
44+
node.asExpr().getUnspecifiedType() instanceof IntegralType
45+
}
46+
47+
predicate isBarrierIn(DataFlow::Node node) {
3748
exists(SqlBarrierFunction sql, int arg, FunctionInput input |
38-
e = sql.getACallToThisFunction().getArgument(arg) and
49+
node.asIndirectArgument() = sql.getACallToThisFunction().getArgument(arg) and
3950
input.isParameterDeref(arg) and
4051
sql.barrierSqlArgument(input, _)
4152
)
4253
}
4354
}
4455

56+
module SqlTainted = TaintTracking::Global<SqlTaintedConfig>;
57+
4558
from
46-
SqlLikeFunction runSql, Expr taintedArg, Expr taintSource, PathNode sourceNode, PathNode sinkNode,
47-
string taintCause, string callChain
59+
SqlLikeFunction runSql, Expr taintedArg, FlowSource taintSource, SqlTainted::PathNode sourceNode,
60+
SqlTainted::PathNode sinkNode, string callChain
4861
where
4962
runSql.outermostWrapperFunctionCall(taintedArg, callChain) and
50-
taintedWithPath(taintSource, taintedArg, sourceNode, sinkNode) and
51-
isUserInput(taintSource, taintCause)
63+
SqlTainted::flowPath(sourceNode, sinkNode) and
64+
taintedArg = asSinkExpr(sinkNode.getNode()) and
65+
taintSource = sourceNode.getNode()
5266
select taintedArg, sourceNode, sinkNode,
5367
"This argument to a SQL query function is derived from $@ and then passed to " + callChain + ".",
54-
taintSource, "user input (" + taintCause + ")"
68+
taintSource, "user input (" + taintSource.getSourceType() + ")"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Some queries that had repeated results corresponding to different levels of indirection for `argv` now only have a single result.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `cpp/non-constant-format` query no longer considers an assignment on the right-hand side of another assignment to be a source of non-constant format strings. As a result, the query may now produce fewer results.

cpp/ql/src/experimental/Security/CWE/CWE-078/WordexpTainted.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module WordexpTaintConfig implements DataFlow::ConfigSig {
4040

4141
predicate isSink(DataFlow::Node sink) {
4242
exists(FunctionCall fc | fc.getTarget() instanceof WordexpFunction |
43-
fc.getArgument(0) = sink.asExpr() and
43+
fc.getArgument(0) = sink.asIndirectArgument(1) and
4444
not isCommandSubstitutionDisabled(fc)
4545
)
4646
}
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
edges
2-
| test.cpp:22:27:22:30 | argv | test.cpp:29:13:29:20 | filePath |
3-
| test.cpp:22:27:22:30 | argv | test.cpp:29:13:29:20 | filePath |
4-
| test.cpp:22:27:22:30 | argv indirection | test.cpp:29:13:29:20 | filePath |
5-
| test.cpp:22:27:22:30 | argv indirection | test.cpp:29:13:29:20 | filePath |
2+
| test.cpp:22:27:22:30 | argv indirection | test.cpp:29:13:29:20 | filePath indirection |
63
nodes
7-
| test.cpp:22:27:22:30 | argv | semmle.label | argv |
84
| test.cpp:22:27:22:30 | argv indirection | semmle.label | argv indirection |
9-
| test.cpp:29:13:29:20 | filePath | semmle.label | filePath |
10-
| test.cpp:29:13:29:20 | filePath | semmle.label | filePath |
5+
| test.cpp:29:13:29:20 | filePath indirection | semmle.label | filePath indirection |
116
subpaths
127
#select
13-
| test.cpp:29:13:29:20 | filePath | test.cpp:22:27:22:30 | argv | test.cpp:29:13:29:20 | filePath | Using user-supplied data in a `wordexp` command, without disabling command substitution, can make code vulnerable to command injection. |
14-
| test.cpp:29:13:29:20 | filePath | test.cpp:22:27:22:30 | argv | test.cpp:29:13:29:20 | filePath | Using user-supplied data in a `wordexp` command, without disabling command substitution, can make code vulnerable to command injection. |
15-
| test.cpp:29:13:29:20 | filePath | test.cpp:22:27:22:30 | argv indirection | test.cpp:29:13:29:20 | filePath | Using user-supplied data in a `wordexp` command, without disabling command substitution, can make code vulnerable to command injection. |
16-
| test.cpp:29:13:29:20 | filePath | test.cpp:22:27:22:30 | argv indirection | test.cpp:29:13:29:20 | filePath | Using user-supplied data in a `wordexp` command, without disabling command substitution, can make code vulnerable to command injection. |
8+
| test.cpp:29:13:29:20 | filePath indirection | test.cpp:22:27:22:30 | argv indirection | test.cpp:29:13:29:20 | filePath indirection | Using user-supplied data in a `wordexp` command, without disabling command substitution, can make code vulnerable to command injection. |

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,23 @@ ir.c:
17981798
# 10| Type = [CTypedefType] MyCoords
17991799
# 10| ValueCategory = lvalue
18001800
# 11| getStmt(3): [ReturnStmt] return ...
1801+
# 13| [TopLevelFunction] void CStyleCast(void*)
1802+
# 13| <params>:
1803+
# 13| getParameter(0): [Parameter] src
1804+
# 13| Type = [VoidPointerType] void *
1805+
# 14| getEntryPoint(): [BlockStmt] { ... }
1806+
# 15| getStmt(0): [DeclStmt] declaration
1807+
# 15| getDeclarationEntry(0): [VariableDeclarationEntry] definition of dst
1808+
# 15| Type = [CharPointerType] char *
1809+
# 15| getVariable().getInitializer(): [Initializer] initializer for dst
1810+
# 15| getExpr(): [VariableAccess] src
1811+
# 15| Type = [VoidPointerType] void *
1812+
# 15| ValueCategory = prvalue(load)
1813+
# 15| getExpr().getFullyConverted(): [CStyleCast] (char *)...
1814+
# 15| Conversion = [PointerConversion] pointer conversion
1815+
# 15| Type = [CharPointerType] char *
1816+
# 15| ValueCategory = prvalue
1817+
# 16| getStmt(1): [ReturnStmt] return ...
18011818
ir.cpp:
18021819
# 1| [TopLevelFunction] void Constants()
18031820
# 1| <params>:

cpp/ql/test/library-tests/ir/ir/ir.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ void MyCoordsTest(int pos) {
99
coords.x = coords.y = pos + 1;
1010
coords.x = getX(&coords);
1111
}
12+
13+
void CStyleCast(void *src)
14+
{
15+
char *dst = (char*)src;
16+
}
17+
18+
// semmle-extractor-options: --microsoft

0 commit comments

Comments
 (0)