Skip to content

Commit 9f9c486

Browse files
committed
Merge branch 'main' into mathiasvp/replace-ast-with-ir-use-usedataflow
2 parents ecbcee5 + 522c9d6 commit 9f9c486

File tree

69 files changed

+15065
-5966
lines changed

Some content is hidden

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

69 files changed

+15065
-5966
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
version: 2
22
updates:
33
- package-ecosystem: "cargo"
4-
directory: "ruby/node-types"
5-
schedule:
6-
interval: "daily"
7-
- package-ecosystem: "cargo"
8-
directory: "ruby/generator"
9-
schedule:
10-
interval: "daily"
11-
- package-ecosystem: "cargo"
12-
directory: "ruby/extractor"
13-
schedule:
14-
interval: "daily"
15-
- package-ecosystem: "cargo"
16-
directory: "ruby/autobuilder"
4+
directory: "ruby"
175
schedule:
186
interval: "daily"
197

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -142,33 +142,9 @@ predicate modeledTaintStep(DataFlow::Node nodeIn, DataFlow::Node nodeOut) {
142142
call.getStaticCallTarget() = func and
143143
func.hasTaintFlow(modelIn, modelOut)
144144
|
145-
(
146-
nodeIn = callInput(call, modelIn)
147-
or
148-
exists(int n |
149-
modelIn.isParameterDerefOrQualifierObject(n) and
150-
if n = -1
151-
then nodeIn = callInput(call, any(InQualifierAddress inQualifier))
152-
else nodeIn = callInput(call, any(InParameter inParam | inParam.getIndex() = n))
153-
)
154-
) and
155-
nodeOut = callOutput(call, modelOut)
145+
nodeIn = callInput(call, modelIn) and nodeOut = callOutput(call, modelOut)
156146
or
157-
exists(int d |
158-
nodeIn = callInput(call, modelIn, d)
159-
or
160-
exists(int n |
161-
d = 1 and
162-
modelIn.isParameterDerefOrQualifierObject(n) and
163-
if n = -1
164-
then nodeIn = callInput(call, any(InQualifierAddress inQualifier))
165-
else nodeIn = callInput(call, any(InParameter inParam | inParam.getIndex() = n))
166-
)
167-
|
168-
call.getStaticCallTarget() = func and
169-
func.hasTaintFlow(modelIn, modelOut) and
170-
nodeOut = callOutput(call, modelOut, d)
171-
)
147+
exists(int d | nodeIn = callInput(call, modelIn, d) and nodeOut = callOutput(call, modelOut, d))
172148
)
173149
or
174150
// Taint flow from one argument to another and data flow from an argument to a

cpp/ql/lib/semmle/code/cpp/models/implementations/Iterator.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private class IteratorAssignArithmeticOperatorModel extends IteratorAssignArithm
206206
input.isReturnValueDeref() and
207207
output.isParameterDeref(0)
208208
or
209-
input.isParameterDeref(1) and
209+
(input.isParameter(1) or input.isParameterDeref(1)) and
210210
output.isParameterDeref(0)
211211
}
212212
}
@@ -305,7 +305,7 @@ private class IteratorAssignArithmeticMemberOperator extends MemberFunction, Dat
305305
input.isReturnValueDeref() and
306306
output.isQualifierObject()
307307
or
308-
input.isParameterDeref(0) and
308+
(input.isParameter(0) or input.isParameterDeref(0)) and
309309
output.isQualifierObject()
310310
}
311311
}

cpp/ql/lib/semmle/code/cpp/models/implementations/StdSet.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ private class StdSetConstructor extends Constructor, TaintFunction {
2727

2828
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
2929
// taint flow from any parameter of an iterator type to the qualifier
30-
input.isParameterDeref(this.getAnIteratorParameterIndex()) and
30+
(
31+
// AST dataflow doesn't have indirection for iterators.
32+
// Once we deprecate AST dataflow we can delete this first disjunct.
33+
input.isParameter(this.getAnIteratorParameterIndex()) or
34+
input.isParameterDeref(this.getAnIteratorParameterIndex())
35+
) and
3136
(
3237
output.isReturnValue() // TODO: this is only needed for AST data flow, which treats constructors as returning the new object
3338
or
@@ -45,7 +50,12 @@ private class StdSetInsert extends TaintFunction {
4550
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
4651
// flow from last parameter to qualifier and return value
4752
// (where the return value is a pair, this should really flow just to the first part of it)
48-
input.isParameterDeref(this.getNumberOfParameters() - 1) and
53+
(
54+
// AST dataflow doesn't have indirection for iterators.
55+
// Once we deprecate AST dataflow we can delete this first disjunct.
56+
input.isParameter(this.getNumberOfParameters() - 1) or
57+
input.isParameterDeref(this.getNumberOfParameters() - 1)
58+
) and
4959
(
5060
output.isQualifierObject() or
5161
output.isReturnValue()

cpp/ql/lib/semmle/code/cpp/models/implementations/StdString.qll

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ private class StdBasicStringIterator extends Iterator, Type {
3838
*/
3939
abstract private class StdStringTaintFunction extends TaintFunction {
4040
/**
41-
* Gets the index of a parameter to this function that is a string (or
42-
* character).
41+
* Gets the index of a parameter to this function that is a string.
4342
*/
4443
final int getAStringParameterIndex() {
4544
exists(Type paramType | paramType = this.getParameter(result).getUnspecifiedType() |
@@ -50,7 +49,14 @@ abstract private class StdStringTaintFunction extends TaintFunction {
5049
paramType instanceof ReferenceType and
5150
not paramType.(ReferenceType).getBaseType() =
5251
this.getDeclaringType().getTemplateArgument(2).(Type).getUnspecifiedType()
53-
or
52+
)
53+
}
54+
55+
/**
56+
* Gets the index of a parameter to this function that is a character.
57+
*/
58+
final int getACharParameterIndex() {
59+
exists(Type paramType | paramType = this.getParameter(result).getUnspecifiedType() |
5460
// i.e. `std::basic_string::CharT`
5561
paramType = this.getDeclaringType().getTemplateArgument(0).(Type).getUnspecifiedType()
5662
)
@@ -79,6 +85,7 @@ private class StdStringConstructor extends Constructor, StdStringTaintFunction {
7985
// taint flow from any parameter of the value type to the returned object
8086
(
8187
input.isParameterDeref(this.getAStringParameterIndex()) or
88+
input.isParameter(this.getACharParameterIndex()) or
8289
input.isParameter(this.getAnIteratorParameterIndex())
8390
) and
8491
(
@@ -128,7 +135,7 @@ private class StdStringPush extends StdStringTaintFunction {
128135

129136
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
130137
// flow from parameter to qualifier
131-
input.isParameterDeref(0) and
138+
input.isParameter(0) and
132139
output.isQualifierObject()
133140
}
134141
}
@@ -180,6 +187,7 @@ private class StdStringAppend extends StdStringTaintFunction {
180187
(
181188
input.isQualifierObject() or
182189
input.isParameterDeref(this.getAStringParameterIndex()) or
190+
input.isParameter(this.getACharParameterIndex()) or
183191
input.isParameter(this.getAnIteratorParameterIndex())
184192
) and
185193
(
@@ -210,6 +218,7 @@ private class StdStringInsert extends StdStringTaintFunction {
210218
(
211219
input.isQualifierObject() or
212220
input.isParameterDeref(this.getAStringParameterIndex()) or
221+
input.isParameter(this.getACharParameterIndex()) or
213222
input.isParameter(this.getAnIteratorParameterIndex())
214223
) and
215224
(
@@ -236,6 +245,7 @@ private class StdStringAssign extends StdStringTaintFunction {
236245
// flow from parameter to string itself (qualifier) and return value
237246
(
238247
input.isParameterDeref(this.getAStringParameterIndex()) or
248+
input.isParameter(this.getACharParameterIndex()) or
239249
input.isParameter(this.getAnIteratorParameterIndex())
240250
) and
241251
(

cpp/ql/lib/semmle/code/cpp/models/interfaces/FormattingFunction.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@ abstract class FormattingFunction extends ArrayFunction, TaintFunction {
158158

159159
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
160160
exists(int arg |
161-
(
162-
arg = getFormatParameterIndex() or
163-
arg >= getFirstFormatArgumentIndex()
164-
) and
165-
input.isParameterDeref(arg) and
161+
arg = getFormatParameterIndex() or
162+
arg >= getFirstFormatArgumentIndex()
163+
|
164+
(input.isParameterDeref(arg) or input.isParameter(arg)) and
166165
output.isParameterDeref(getOutputParameterIndex(_))
167166
)
168167
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Expression extends @expr {
2+
string toString() { none() }
3+
}
4+
5+
class TypeOrRef extends @type_or_ref {
6+
string toString() { none() }
7+
}
8+
9+
from Expression e, int k, int kind, TypeOrRef t
10+
where
11+
expressions(e, k, t) and
12+
if k = 135 then kind = 106 else kind = k
13+
select e, kind, t

0 commit comments

Comments
 (0)