Skip to content

Commit a17cd9b

Browse files
authored
Merge pull request #14667 from MathiasVP/more-function-input-and-output-ipa-numbers
C++: Allocate more `FunctionInput` and `FunctionOutput`s
2 parents 4ce8d95 + 31c2a3b commit a17cd9b

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private class Getaddrinfo extends TaintFunction, ArrayFunction, RemoteFlowSource
157157
override predicate hasArrayWithNullTerminator(int bufParam) { bufParam in [0, 1] }
158158

159159
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
160-
output.isParameterDeref(3) and
160+
output.isParameterDeref(3, 2) and
161161
description = "address returned by " + this.getName()
162162
}
163163
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private class Send extends AliasFunction, ArrayFunction, SideEffectFunction, Rem
5858
override ParameterIndex getParameterSizeIndex(ParameterIndex i) { i = 1 and result = 2 }
5959

6060
override predicate hasRemoteFlowSink(FunctionInput input, string description) {
61-
input.isParameterDeref(1) and description = "buffer sent by " + this.getName()
61+
input.isParameterDeref(1, 1) and description = "buffer sent by " + this.getName()
6262
}
6363

6464
override predicate hasSocketInput(FunctionInput input) { input.isParameter(0) }

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import semmle.code.cpp.Parameter
88

99
private newtype TFunctionInput =
1010
TInParameter(ParameterIndex i) or
11-
TInParameterDeref(ParameterIndex i) or
11+
TInParameterDeref(ParameterIndex i, int indirectionIndex) { indirectionIndex = [1, 2] } or
1212
TInQualifierObject() or
1313
TInQualifierAddress() or
1414
TInReturnValueDeref()
@@ -245,15 +245,18 @@ class InParameter extends FunctionInput, TInParameter {
245245
*/
246246
class InParameterDeref extends FunctionInput, TInParameterDeref {
247247
ParameterIndex index;
248+
int indirectionIndex;
248249

249-
InParameterDeref() { this = TInParameterDeref(index) }
250+
InParameterDeref() { this = TInParameterDeref(index, indirectionIndex) }
250251

251252
override string toString() { result = "InParameterDeref " + index.toString() }
252253

253254
/** Gets the zero-based index of the parameter. */
254255
ParameterIndex getIndex() { result = index }
255256

256-
override predicate isParameterDeref(ParameterIndex i) { i = index }
257+
override predicate isParameterDeref(ParameterIndex i, int indirection) {
258+
i = index and indirectionIndex = indirection
259+
}
257260
}
258261

259262
/**
@@ -321,10 +324,10 @@ class InReturnValueDeref extends FunctionInput, TInReturnValueDeref {
321324
}
322325

323326
private newtype TFunctionOutput =
324-
TOutParameterDeref(ParameterIndex i) or
327+
TOutParameterDeref(ParameterIndex i, int indirectionIndex) { indirectionIndex = [1, 2] } or
325328
TOutQualifierObject() or
326329
TOutReturnValue() or
327-
TOutReturnValueDeref()
330+
TOutReturnValueDeref(int indirections) { indirections = [1, 2] }
328331

329332
/**
330333
* An output from a function. This can be:
@@ -498,17 +501,16 @@ class FunctionOutput extends TFunctionOutput {
498501
*/
499502
class OutParameterDeref extends FunctionOutput, TOutParameterDeref {
500503
ParameterIndex index;
504+
int indirectionIndex;
501505

502-
OutParameterDeref() { this = TOutParameterDeref(index) }
506+
OutParameterDeref() { this = TOutParameterDeref(index, indirectionIndex) }
503507

504508
override string toString() { result = "OutParameterDeref " + index.toString() }
505509

506510
ParameterIndex getIndex() { result = index }
507511

508-
override predicate isParameterDeref(ParameterIndex i) { i = index }
509-
510512
override predicate isParameterDeref(ParameterIndex i, int ind) {
511-
this.isParameterDeref(i) and ind = 1
513+
i = index and ind = indirectionIndex
512514
}
513515
}
514516

@@ -572,4 +574,8 @@ class OutReturnValueDeref extends FunctionOutput, TOutReturnValueDeref {
572574
override string toString() { result = "OutReturnValueDeref" }
573575

574576
override predicate isReturnValueDeref() { any() }
577+
578+
override predicate isReturnValueDeref(int indirectionIndex) {
579+
this = TOutReturnValueDeref(indirectionIndex)
580+
}
575581
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
failures
21
testFailures
2+
failures

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6646,6 +6646,17 @@ WARNING: Module TaintTracking has been deprecated and may be removed in future (
66466646
| taint.cpp:738:17:738:31 | call to indirect_source | taint.cpp:739:30:739:35 | source | |
66476647
| taint.cpp:739:22:739:28 | call to realloc | taint.cpp:740:7:740:10 | dest | |
66486648
| taint.cpp:739:30:739:35 | source | taint.cpp:739:22:739:28 | call to realloc | TAINT |
6649+
| taint.cpp:743:40:743:45 | buffer | taint.cpp:744:5:744:10 | buffer | |
6650+
| taint.cpp:743:40:743:45 | buffer | taint.cpp:745:27:745:32 | buffer | |
6651+
| taint.cpp:744:4:744:10 | * ... | taint.cpp:744:3:744:10 | * ... | TAINT |
6652+
| taint.cpp:744:5:744:10 | buffer | taint.cpp:744:4:744:10 | * ... | TAINT |
6653+
| taint.cpp:744:14:744:19 | call to source | taint.cpp:744:3:744:21 | ... = ... | |
6654+
| taint.cpp:745:19:745:25 | call to realloc | taint.cpp:743:40:743:45 | buffer | |
6655+
| taint.cpp:745:19:745:25 | call to realloc | taint.cpp:745:3:745:37 | ... = ... | |
6656+
| taint.cpp:745:19:745:25 | call to realloc | taint.cpp:746:10:746:15 | buffer | |
6657+
| taint.cpp:745:27:745:32 | buffer | taint.cpp:745:19:745:25 | call to realloc | TAINT |
6658+
| taint.cpp:746:9:746:15 | * ... | taint.cpp:746:8:746:15 | * ... | TAINT |
6659+
| taint.cpp:746:10:746:15 | buffer | taint.cpp:746:9:746:15 | * ... | TAINT |
66496660
| vector.cpp:16:43:16:49 | source1 | vector.cpp:17:26:17:32 | source1 | |
66506661
| vector.cpp:16:43:16:49 | source1 | vector.cpp:31:38:31:44 | source1 | |
66516662
| vector.cpp:17:21:17:33 | call to vector | vector.cpp:19:14:19:14 | v | |

cpp/ql/test/library-tests/dataflow/taint-tests/taint.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,4 +738,10 @@ void test_realloc() {
738738
char *source = indirect_source();
739739
char *dest = (char*)realloc(source, 16);
740740
sink(dest); // $ ir MISSING: ast
741+
}
742+
743+
void test_realloc_2_indirections(int **buffer) {
744+
**buffer = source();
745+
buffer = (int**)realloc(buffer, 16);
746+
sink(**buffer); // $ ir MISSING: ast
741747
}

0 commit comments

Comments
 (0)