Skip to content

Commit 6dcfe03

Browse files
committed
C++: Copy over the required changes to non-experimental libraries.
1 parent 5509562 commit 6dcfe03

File tree

5 files changed

+141
-16
lines changed

5 files changed

+141
-16
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/ir/dataflow/TaintTracking.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ import semmle.code.cpp.ir.dataflow.DataFlow
1919
import semmle.code.cpp.ir.dataflow.DataFlow2
2020

2121
module TaintTracking {
22-
import semmle.code.cpp.ir.dataflow.internal.tainttracking1.TaintTrackingImpl
22+
import experimental.semmle.code.cpp.ir.dataflow.internal.tainttracking1.TaintTrackingImpl
2323
}

cpp/ql/lib/experimental/semmle/code/cpp/ir/dataflow/TaintTracking2.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
* See `semmle.code.cpp.ir.dataflow.TaintTracking` for the full documentation.
1212
*/
1313
module TaintTracking2 {
14-
import semmle.code.cpp.ir.dataflow.internal.tainttracking2.TaintTrackingImpl
14+
import experimental.semmle.code.cpp.ir.dataflow.internal.tainttracking2.TaintTrackingImpl
1515
}

cpp/ql/lib/experimental/semmle/code/cpp/ir/dataflow/TaintTracking3.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
* See `semmle.code.cpp.ir.dataflow.TaintTracking` for the full documentation.
1212
*/
1313
module TaintTracking3 {
14-
import semmle.code.cpp.ir.dataflow.internal.tainttracking3.TaintTrackingImpl
14+
import experimental.semmle.code.cpp.ir.dataflow.internal.tainttracking3.TaintTrackingImpl
1515
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/SideEffects.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,15 @@ private predicate isDeeplyConstBelow(Type t) {
5555
isDeeplyConstBelow(t.(TypedefType).getBaseType())
5656
}
5757

58-
private predicate isConstPointerLike(Type t) {
58+
/**
59+
* INTERNAL: Do not use.
60+
*
61+
* Holds if `t` is a pointer-like type (i.e., a pointer,
62+
* an array a reference, or a pointer-wrapper such as
63+
* `std::unique_ptr`) that is constant and only contains
64+
* constant types, excluding the type itself.
65+
*/
66+
predicate isConstPointerLike(Type t) {
5967
(
6068
t instanceof PointerWrapper
6169
or

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

Lines changed: 129 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ class FunctionInput extends TFunctionInput {
4646
*/
4747
deprecated final predicate isInParameter(ParameterIndex index) { this.isParameter(index) }
4848

49+
/**
50+
* Holds if this is the input value pointed to by a pointer parameter to a function, or the input
51+
* value referred to by a reference parameter to a function, where the parameter has index
52+
* `index`.
53+
*
54+
* Example:
55+
* ```
56+
* void func(int n, char* p, float& r);
57+
* ```
58+
* - `isParameterDeref(1, 1)` holds for the `FunctionInput` that represents the value of `*p` (with
59+
* type `char`) on entry to the function.
60+
* - `isParameterDeref(2, 1)` holds for the `FunctionInput` that represents the value of `r` (with type
61+
* `float`) on entry to the function.
62+
* - There is no `FunctionInput` for which `isParameterDeref(0, _)` holds, because `n` is neither a
63+
* pointer nor a reference.
64+
*/
65+
predicate isParameterDeref(ParameterIndex index, int ind) {
66+
ind = 1 and this.isParameterDeref(index)
67+
}
68+
4969
/**
5070
* Holds if this is the input value pointed to by a pointer parameter to a function, or the input
5171
* value referred to by a reference parameter to a function, where the parameter has index
@@ -62,7 +82,7 @@ class FunctionInput extends TFunctionInput {
6282
* - There is no `FunctionInput` for which `isParameterDeref(0)` holds, because `n` is neither a
6383
* pointer nor a reference.
6484
*/
65-
predicate isParameterDeref(ParameterIndex index) { none() }
85+
predicate isParameterDeref(ParameterIndex index) { this.isParameterDeref(index, 1) }
6686

6787
/**
6888
* Holds if this is the input value pointed to by a pointer parameter to a function, or the input
@@ -87,7 +107,22 @@ class FunctionInput extends TFunctionInput {
87107
* - `isQualifierObject()` holds for the `FunctionInput` that represents the value of `*this`
88108
* (with type `C const`) on entry to the function.
89109
*/
90-
predicate isQualifierObject() { none() }
110+
predicate isQualifierObject(int ind) { ind = 1 and this.isQualifierObject() }
111+
112+
/**
113+
* Holds if this is the input value pointed to by the `this` pointer of an instance member
114+
* function.
115+
*
116+
* Example:
117+
* ```
118+
* struct C {
119+
* void mfunc(int n, char* p, float& r) const;
120+
* };
121+
* ```
122+
* - `isQualifierObject()` holds for the `FunctionInput` that represents the value of `*this`
123+
* (with type `C const`) on entry to the function.
124+
*/
125+
predicate isQualifierObject() { this.isQualifierObject(1) }
91126

92127
/**
93128
* Holds if this is the input value pointed to by the `this` pointer of an instance member
@@ -143,16 +178,49 @@ class FunctionInput extends TFunctionInput {
143178
* rare, but they do occur when a function returns a reference to itself,
144179
* part of itself, or one of its other inputs.
145180
*/
146-
predicate isReturnValueDeref() { none() }
181+
predicate isReturnValueDeref() { this.isReturnValueDeref(1) }
182+
183+
/**
184+
* Holds if this is the input value pointed to by the return value of a
185+
* function, if the function returns a pointer, or the input value referred
186+
* to by the return value of a function, if the function returns a reference.
187+
*
188+
* Example:
189+
* ```
190+
* char* getPointer();
191+
* float& getReference();
192+
* int getInt();
193+
* ```
194+
* - `isReturnValueDeref(1)` holds for the `FunctionInput` that represents the
195+
* value of `*getPointer()` (with type `char`).
196+
* - `isReturnValueDeref(1)` holds for the `FunctionInput` that represents the
197+
* value of `getReference()` (with type `float`).
198+
* - There is no `FunctionInput` of `getInt()` for which
199+
* `isReturnValueDeref(_)` holds because the return type of `getInt()` is
200+
* neither a pointer nor a reference.
201+
*
202+
* Note that data flows in through function return values are relatively
203+
* rare, but they do occur when a function returns a reference to itself,
204+
* part of itself, or one of its other inputs.
205+
*/
206+
predicate isReturnValueDeref(int ind) { ind = 1 and this.isReturnValueDeref() }
147207

148208
/**
149209
* Holds if `i >= 0` and `isParameterDeref(i)` holds for this value, or
150210
* if `i = -1` and `isQualifierObject()` holds for this value.
151211
*/
152-
final predicate isParameterDerefOrQualifierObject(ParameterIndex i) {
153-
i >= 0 and this.isParameterDeref(i)
212+
final predicate isParameterDerefOrQualifierObject(ParameterIndex i, int ind) {
213+
i >= 0 and this.isParameterDeref(i, ind)
154214
or
155-
i = -1 and this.isQualifierObject()
215+
i = -1 and this.isQualifierObject(ind)
216+
}
217+
218+
/**
219+
* Holds if `i >= 0` and `isParameterDeref(i)` holds for this value, or
220+
* if `i = -1` and `isQualifierObject()` holds for this value.
221+
*/
222+
final predicate isParameterDerefOrQualifierObject(ParameterIndex i) {
223+
this.isParameterDerefOrQualifierObject(i, 1)
156224
}
157225
}
158226

@@ -308,7 +376,9 @@ class FunctionOutput extends TFunctionOutput {
308376
* - There is no `FunctionOutput` for which `isParameterDeref(0)` holds, because `n` is neither a
309377
* pointer nor a reference.
310378
*/
311-
predicate isParameterDeref(ParameterIndex i) { none() }
379+
predicate isParameterDeref(ParameterIndex i) { this.isParameterDeref(i, 1) }
380+
381+
predicate isParameterDeref(ParameterIndex i, int ind) { ind = 1 and this.isParameterDeref(i) }
312382

313383
/**
314384
* Holds if this is the output value pointed to by a pointer parameter to a function, or the
@@ -333,7 +403,22 @@ class FunctionOutput extends TFunctionOutput {
333403
* - `isQualifierObject()` holds for the `FunctionOutput` that represents the value of `*this`
334404
* (with type `C`) on return from the function.
335405
*/
336-
predicate isQualifierObject() { none() }
406+
predicate isQualifierObject() { this.isQualifierObject(1) }
407+
408+
/**
409+
* Holds if this is the output value pointed to by the `this` pointer of an instance member
410+
* function.
411+
*
412+
* Example:
413+
* ```
414+
* struct C {
415+
* void mfunc(int n, char* p, float& r);
416+
* };
417+
* ```
418+
* - `isQualifierObject()` holds for the `FunctionOutput` that represents the value of `*this`
419+
* (with type `C`) on return from the function.
420+
*/
421+
predicate isQualifierObject(int ind) { ind = 1 and this.isQualifierObject() }
337422

338423
/**
339424
* Holds if this is the output value pointed to by the `this` pointer of an instance member
@@ -385,7 +470,27 @@ class FunctionOutput extends TFunctionOutput {
385470
* - There is no `FunctionOutput` of `getInt()` for which `isReturnValueDeref()` holds because the
386471
* return type of `getInt()` is neither a pointer nor a reference.
387472
*/
388-
predicate isReturnValueDeref() { none() }
473+
predicate isReturnValueDeref() { this.isReturnValueDeref(_) }
474+
475+
/**
476+
* Holds if this is the output value pointed to by the return value of a function, if the function
477+
* returns a pointer, or the output value referred to by the return value of a function, if the
478+
* function returns a reference.
479+
*
480+
* Example:
481+
* ```
482+
* char* getPointer();
483+
* float& getReference();
484+
* int getInt();
485+
* ```
486+
* - `isReturnValueDeref(1)` holds for the `FunctionOutput` that represents the value of
487+
* `*getPointer()` (with type `char`).
488+
* - `isReturnValueDeref(1)` holds for the `FunctionOutput` that represents the value of
489+
* `getReference()` (with type `float`).
490+
* - There is no `FunctionOutput` of `getInt()` for which `isReturnValueDeref(_)` holds because the
491+
* return type of `getInt()` is neither a pointer nor a reference.
492+
*/
493+
predicate isReturnValueDeref(int ind) { ind = 1 and this.isReturnValueDeref() }
389494

390495
/**
391496
* Holds if this is the output value pointed to by the return value of a function, if the function
@@ -399,10 +504,18 @@ class FunctionOutput extends TFunctionOutput {
399504
* Holds if `i >= 0` and `isParameterDeref(i)` holds for this is the value, or
400505
* if `i = -1` and `isQualifierObject()` holds for this value.
401506
*/
402-
final predicate isParameterDerefOrQualifierObject(ParameterIndex i) {
403-
i >= 0 and this.isParameterDeref(i)
507+
final predicate isParameterDerefOrQualifierObject(ParameterIndex i, int ind) {
508+
i >= 0 and this.isParameterDeref(i, ind)
404509
or
405-
i = -1 and this.isQualifierObject()
510+
i = -1 and this.isQualifierObject(ind)
511+
}
512+
513+
/**
514+
* Holds if `i >= 0` and `isParameterDeref(i)` holds for this is the value, or
515+
* if `i = -1` and `isQualifierObject()` holds for this value.
516+
*/
517+
final predicate isParameterDerefOrQualifierObject(ParameterIndex i) {
518+
this.isParameterDerefOrQualifierObject(i, 1)
406519
}
407520
}
408521

@@ -431,6 +544,10 @@ class OutParameterDeref extends FunctionOutput, TOutParameterDeref {
431544
ParameterIndex getIndex() { result = index }
432545

433546
override predicate isParameterDeref(ParameterIndex i) { i = index }
547+
548+
override predicate isParameterDeref(ParameterIndex i, int ind) {
549+
this.isParameterDeref(i) and ind = 1
550+
}
434551
}
435552

436553
/**

0 commit comments

Comments
 (0)