Skip to content

Commit 9bcdfb6

Browse files
committed
C++: VariableAddressInstructions with array types are not single-object types.
1 parent 41425b1 commit 9bcdfb6

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ private module Input implements TypeFlowInput<Location> {
2727
}
2828

2929
private predicate hasExactSingleType(Instruction i) {
30-
// The address of a variable is always a single object
31-
i instanceof VariableAddressInstruction
30+
// The address of a variable is always a single object (unless it's an array)
31+
exists(VariableAddressInstruction vai |
32+
i = vai and
33+
not vai.getResultType() instanceof ArrayType
34+
)
3235
or
3336
// A reference always points to a single object
3437
i.getResultLanguageType().hasUnspecifiedType(any(ReferenceType rt), false)

cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ irFlow
326326
| test.cpp:1069:9:1069:14 | call to source | test.cpp:1081:10:1081:10 | i |
327327
| test.cpp:1117:27:1117:34 | call to source | test.cpp:1117:27:1117:34 | call to source |
328328
| test.cpp:1132:11:1132:16 | call to source | test.cpp:1121:8:1121:8 | x |
329+
| test.cpp:1138:17:1138:22 | call to source | test.cpp:1140:8:1140:18 | * ... |
329330
| true_upon_entry.cpp:9:11:9:16 | call to source | true_upon_entry.cpp:13:8:13:8 | x |
330331
| true_upon_entry.cpp:17:11:17:16 | call to source | true_upon_entry.cpp:21:8:21:8 | x |
331332
| true_upon_entry.cpp:27:9:27:14 | call to source | true_upon_entry.cpp:29:8:29:8 | x |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,5 +1137,5 @@ void test_uncertain_array(int n1, int n2) {
11371137
int data[10];
11381138
*(data + 1) = source();
11391139
*data = 0;
1140-
sink(*(data + 1)); // $ ast=1138:17 ast=1137:7 MISSING: ir
1140+
sink(*(data + 1)); // $ ast=1138:17 ast=1137:7 ir
11411141
}

0 commit comments

Comments
 (0)