Skip to content

Commit ca5916f

Browse files
authored
Merge pull request github#11946 from MathiasVP/fix-taint-models-2
2 parents c512edd + 470abfd commit ca5916f

File tree

5 files changed

+35
-24
lines changed

5 files changed

+35
-24
lines changed

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,11 @@ predicate defaultTaintSanitizer(DataFlow::Node node) { none() }
169169
*/
170170
predicate modeledTaintStep(Operand nodeIn, Instruction nodeOut) {
171171
exists(CallInstruction call, TaintFunction func, FunctionInput modelIn, FunctionOutput modelOut |
172-
(
173-
nodeIn = callInput(call, modelIn)
174-
or
175-
exists(int n |
176-
modelIn.isParameterDerefOrQualifierObject(n) and
177-
if n = -1
178-
then nodeIn = callInput(call, any(InQualifierObject inQualifier))
179-
else nodeIn = callInput(call, any(InParameter inParam | inParam.getIndex() = n))
180-
)
181-
) and
182-
nodeOut = callOutput(call, modelOut) and
183172
call.getStaticCallTarget() = func and
184173
func.hasTaintFlow(modelIn, modelOut)
174+
|
175+
nodeIn = callInput(call, modelIn) and
176+
nodeOut = callOutput(call, modelOut)
185177
)
186178
or
187179
// 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
}

0 commit comments

Comments
 (0)