Skip to content

Commit 4cb25d8

Browse files
committed
C++: Add isParameterDerefOrQualifierObject helper predicate to FunctionInput and FunctionOutput.
1 parent dea16d4 commit 4cb25d8

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cpp/ql/src/semmle/code/cpp/models/interfaces/FunctionInputsAndOutputs.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ class FunctionInput extends TFunctionInput {
132132
* part of itself, or one of its other inputs.
133133
*/
134134
predicate isReturnValueDeref() { none() }
135+
136+
/**
137+
* Holds if `i >= 0` and `isParameterDeref(i)` holds for this is value, or
138+
* if `i = -1` and `isQualifierObject()` holds for this value.
139+
*/
140+
final predicate isParameterDerefOrQualifierObject(ParameterIndex i) {
141+
i >= 0 and this.isParameterDeref(i)
142+
or
143+
i = -1 and this.isQualifierObject()
144+
}
135145
}
136146

137147
/**
@@ -370,6 +380,16 @@ class FunctionOutput extends TFunctionOutput {
370380
* DEPRECATED: Use `isReturnValueDeref()` instead.
371381
*/
372382
deprecated final predicate isOutReturnPointer() { isReturnValueDeref() }
383+
384+
/**
385+
* Holds if `i >= 0` and `isParameterDeref(i)` holds for this is the value, or
386+
* if `i = -1` and `isQualifierObject()` holds for this value.
387+
*/
388+
final predicate isParameterDerefOrQualifierObject(ParameterIndex i) {
389+
i >= 0 and this.isParameterDeref(i)
390+
or
391+
i = -1 and this.isQualifierObject()
392+
}
373393
}
374394

375395
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private class RemoteParameterSource extends RemoteFlowSource {
4646
asInstruction() = instr and
4747
instr.getPrimaryInstruction().(CallInstruction).getStaticCallTarget() = func and
4848
func.hasRemoteFlowSource(output, sourceType) and
49-
output.isParameterDeref(instr.getIndex())
49+
output.isParameterDerefOrQualifierObject(instr.getIndex())
5050
)
5151
}
5252

@@ -80,7 +80,7 @@ private class LocalParameterSource extends LocalFlowSource {
8080
asInstruction() = instr and
8181
instr.getPrimaryInstruction().(CallInstruction).getStaticCallTarget() = func and
8282
func.hasLocalFlowSource(output, sourceType) and
83-
output.isParameterDeref(instr.getIndex())
83+
output.isParameterDerefOrQualifierObject(instr.getIndex())
8484
)
8585
}
8686

0 commit comments

Comments
 (0)