Skip to content

Commit b4f9b15

Browse files
committed
C++: Restore lost result on git/git. We lost the result in a00bd7a because the added check for type T to type T* conversion didn't handle const qualifiers.
1 parent b0e255e commit b4f9b15

File tree

7 files changed

+50
-5
lines changed

7 files changed

+50
-5
lines changed

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ Type getResultTypeOfSourceValue(CopyValueInstruction copy) {
451451
* pops the `ArrayContent` off the access path when a value-to-pointer or value-to-reference conversion
452452
* happens on the argument that is ends up as the target of such a store.
453453
*/
454-
private predicate innerReadSteap(Node node1, Content a, Node node2) {
454+
private predicate innerReadStep(Node node1, Content a, Node node2) {
455455
a = TArrayContent() and
456456
exists(WriteSideEffectInstruction write, CallInstruction call, CopyValueInstruction copyValue |
457457
write.getPrimaryInstruction() = call and
@@ -463,8 +463,9 @@ private predicate innerReadSteap(Node node1, Content a, Node node2) {
463463
) and
464464
node2.asInstruction() = write and
465465
copyValue = call.getArgument(write.getIndex()) and
466-
[getPointerType(copyValue).getBaseType(), getReferenceType(copyValue).getBaseType()] =
467-
getResultTypeOfSourceValue(copyValue)
466+
// Check that `copyValue` is actually doing a T to a T* conversion.
467+
[getPointerType(copyValue).getBaseType(), getReferenceType(copyValue).getBaseType()].stripType() =
468+
getResultTypeOfSourceValue(copyValue).stripType()
468469
)
469470
}
470471

@@ -477,7 +478,7 @@ predicate readStep(Node node1, Content f, Node node2) {
477478
aliasedReadStep(node1, f, node2) or
478479
arrayReadStep(node1, f, node2) or
479480
instrToFieldNodeReadStep(node1, f, node2) or
480-
innerReadSteap(node1, f, node2)
481+
innerReadStep(node1, f, node2)
481482
}
482483

483484
/**

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void sink(void *o);
1+
void sink(void *o); void sink(const char *o);
22
void *user_input(void);
33

44
struct S {
@@ -135,3 +135,13 @@ void test_outer_with_ref(Outer *pouter) {
135135
sink(pouter->inner_ptr->a); // $ ast MISSING: ir
136136
sink(pouter->a); // $ ast,ir
137137
}
138+
139+
void taint_a_ptr(const char **pa) {
140+
*pa = (char*)user_input();
141+
}
142+
143+
void test_const_char_ref() {
144+
const char* s;
145+
taint_a_ptr(&s);
146+
sink(s); // $ ast ir=140:9 ir=140:16
147+
}

cpp/ql/test/library-tests/dataflow/fields/dataflow-consistency.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ postWithInFlow
123123
| by_reference.cpp:108:24:108:24 | a [inner post update] | PostUpdateNode should not be the target of local flow. |
124124
| by_reference.cpp:123:28:123:36 | inner_ptr [inner post update] | PostUpdateNode should not be the target of local flow. |
125125
| by_reference.cpp:127:30:127:38 | inner_ptr [inner post update] | PostUpdateNode should not be the target of local flow. |
126+
| by_reference.cpp:140:3:140:5 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
127+
| by_reference.cpp:140:4:140:5 | pa [inner post update] | PostUpdateNode should not be the target of local flow. |
128+
| by_reference.cpp:145:16:145:16 | s [inner post update] | PostUpdateNode should not be the target of local flow. |
126129
| complex.cpp:11:22:11:23 | a_ [post update] | PostUpdateNode should not be the target of local flow. |
127130
| complex.cpp:12:22:12:23 | b_ [post update] | PostUpdateNode should not be the target of local flow. |
128131
| conflated.cpp:10:3:10:7 | * ... [post update] | PostUpdateNode should not be the target of local flow. |

cpp/ql/test/library-tests/dataflow/fields/ir-path-flow.expected

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ edges
195195
| by_reference.cpp:134:16:134:27 | inner_nested [a, a] | by_reference.cpp:134:29:134:29 | a [a] |
196196
| by_reference.cpp:134:29:134:29 | a [a] | by_reference.cpp:134:29:134:29 | a |
197197
| by_reference.cpp:136:16:136:16 | a [a] | by_reference.cpp:136:16:136:16 | a |
198+
| by_reference.cpp:140:3:140:27 | Chi [array content] | by_reference.cpp:145:15:145:16 | taint_a_ptr output argument [array content] |
199+
| by_reference.cpp:140:3:140:27 | ChiTotal [post update] [array content] | by_reference.cpp:140:3:140:27 | Chi [array content] |
200+
| by_reference.cpp:140:3:140:27 | ChiTotal [post update] [array content] | by_reference.cpp:145:15:145:16 | taint_a_ptr output argument [array content] |
201+
| by_reference.cpp:140:9:140:27 | (char *)... | by_reference.cpp:140:3:140:27 | ChiTotal [post update] [array content] |
202+
| by_reference.cpp:140:9:140:27 | (const char *)... | by_reference.cpp:140:3:140:27 | ChiTotal [post update] [array content] |
203+
| by_reference.cpp:140:16:140:25 | call to user_input | by_reference.cpp:140:3:140:27 | ChiTotal [post update] [array content] |
204+
| by_reference.cpp:145:15:145:16 | taint_a_ptr output argument | by_reference.cpp:146:8:146:8 | s |
205+
| by_reference.cpp:145:15:145:16 | taint_a_ptr output argument [array content] | by_reference.cpp:145:15:145:16 | taint_a_ptr output argument |
198206
| complex.cpp:40:17:40:17 | *b [a_] | complex.cpp:42:18:42:18 | call to a |
199207
| complex.cpp:40:17:40:17 | *b [b_] | complex.cpp:42:16:42:16 | a output argument [b_] |
200208
| complex.cpp:40:17:40:17 | *b [b_] | complex.cpp:43:18:43:18 | call to b |
@@ -504,6 +512,14 @@ nodes
504512
| by_reference.cpp:134:29:134:29 | a [a] | semmle.label | a [a] |
505513
| by_reference.cpp:136:16:136:16 | a | semmle.label | a |
506514
| by_reference.cpp:136:16:136:16 | a [a] | semmle.label | a [a] |
515+
| by_reference.cpp:140:3:140:27 | Chi [array content] | semmle.label | Chi [array content] |
516+
| by_reference.cpp:140:3:140:27 | ChiTotal [post update] [array content] | semmle.label | ChiTotal [post update] [array content] |
517+
| by_reference.cpp:140:9:140:27 | (char *)... | semmle.label | (char *)... |
518+
| by_reference.cpp:140:9:140:27 | (const char *)... | semmle.label | (const char *)... |
519+
| by_reference.cpp:140:16:140:25 | call to user_input | semmle.label | call to user_input |
520+
| by_reference.cpp:145:15:145:16 | taint_a_ptr output argument | semmle.label | taint_a_ptr output argument |
521+
| by_reference.cpp:145:15:145:16 | taint_a_ptr output argument [array content] | semmle.label | taint_a_ptr output argument [array content] |
522+
| by_reference.cpp:146:8:146:8 | s | semmle.label | s |
507523
| complex.cpp:40:17:40:17 | *b [a_] | semmle.label | *b [a_] |
508524
| complex.cpp:40:17:40:17 | *b [b_] | semmle.label | *b [b_] |
509525
| complex.cpp:40:17:40:17 | *b [f, f, a_] | semmle.label | *b [f, f, a_] |
@@ -649,6 +665,9 @@ nodes
649665
| by_reference.cpp:132:14:132:14 | a | by_reference.cpp:96:8:96:17 | call to user_input | by_reference.cpp:132:14:132:14 | a | a flows from $@ | by_reference.cpp:96:8:96:17 | call to user_input | call to user_input |
650666
| by_reference.cpp:134:29:134:29 | a | by_reference.cpp:88:13:88:22 | call to user_input | by_reference.cpp:134:29:134:29 | a | a flows from $@ | by_reference.cpp:88:13:88:22 | call to user_input | call to user_input |
651667
| by_reference.cpp:136:16:136:16 | a | by_reference.cpp:96:8:96:17 | call to user_input | by_reference.cpp:136:16:136:16 | a | a flows from $@ | by_reference.cpp:96:8:96:17 | call to user_input | call to user_input |
668+
| by_reference.cpp:146:8:146:8 | s | by_reference.cpp:140:9:140:27 | (char *)... | by_reference.cpp:146:8:146:8 | s | s flows from $@ | by_reference.cpp:140:9:140:27 | (char *)... | (char *)... |
669+
| by_reference.cpp:146:8:146:8 | s | by_reference.cpp:140:9:140:27 | (const char *)... | by_reference.cpp:146:8:146:8 | s | s flows from $@ | by_reference.cpp:140:9:140:27 | (const char *)... | (const char *)... |
670+
| by_reference.cpp:146:8:146:8 | s | by_reference.cpp:140:16:140:25 | call to user_input | by_reference.cpp:146:8:146:8 | s | s flows from $@ | by_reference.cpp:140:16:140:25 | call to user_input | call to user_input |
652671
| complex.cpp:42:18:42:18 | call to a | complex.cpp:53:19:53:28 | call to user_input | complex.cpp:42:18:42:18 | call to a | call to a flows from $@ | complex.cpp:53:19:53:28 | call to user_input | call to user_input |
653672
| complex.cpp:42:18:42:18 | call to a | complex.cpp:55:19:55:28 | call to user_input | complex.cpp:42:18:42:18 | call to a | call to a flows from $@ | complex.cpp:55:19:55:28 | call to user_input | call to user_input |
654673
| complex.cpp:43:18:43:18 | call to b | complex.cpp:54:19:54:28 | call to user_input | complex.cpp:43:18:43:18 | call to b | call to b flows from $@ | complex.cpp:54:19:54:28 | call to user_input | call to user_input |

cpp/ql/test/library-tests/dataflow/fields/partial-definition-diff.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@
242242
| by_reference.cpp:134:29:134:29 | a | AST only |
243243
| by_reference.cpp:135:27:135:27 | a | AST only |
244244
| by_reference.cpp:136:16:136:16 | a | AST only |
245+
| by_reference.cpp:140:3:140:5 | * ... | AST only |
246+
| by_reference.cpp:145:15:145:16 | & ... | AST only |
245247
| complex.cpp:9:20:9:21 | this | IR only |
246248
| complex.cpp:10:20:10:21 | this | IR only |
247249
| complex.cpp:11:22:11:23 | a_ | AST only |

cpp/ql/test/library-tests/dataflow/fields/partial-definition.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@
352352
| by_reference.cpp:135:27:135:27 | a |
353353
| by_reference.cpp:136:8:136:13 | pouter |
354354
| by_reference.cpp:136:16:136:16 | a |
355+
| by_reference.cpp:140:3:140:5 | * ... |
356+
| by_reference.cpp:145:15:145:16 | & ... |
355357
| complex.cpp:11:22:11:23 | a_ |
356358
| complex.cpp:11:22:11:23 | this |
357359
| complex.cpp:12:22:12:23 | b_ |

cpp/ql/test/library-tests/dataflow/fields/path-flow.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ edges
323323
| by_reference.cpp:135:8:135:13 | pouter [inner_ptr, a] | by_reference.cpp:135:16:135:24 | inner_ptr [a] |
324324
| by_reference.cpp:135:16:135:24 | inner_ptr [a] | by_reference.cpp:135:27:135:27 | a |
325325
| by_reference.cpp:136:8:136:13 | pouter [a] | by_reference.cpp:136:16:136:16 | a |
326+
| by_reference.cpp:140:4:140:5 | pa [inner post update] | by_reference.cpp:145:15:145:16 | ref arg & ... |
327+
| by_reference.cpp:140:16:140:25 | call to user_input | by_reference.cpp:140:4:140:5 | pa [inner post update] |
328+
| by_reference.cpp:145:15:145:16 | ref arg & ... | by_reference.cpp:146:8:146:8 | s |
326329
| complex.cpp:40:17:40:17 | b [inner, f, a_] | complex.cpp:42:8:42:8 | b [inner, f, a_] |
327330
| complex.cpp:40:17:40:17 | b [inner, f, b_] | complex.cpp:43:8:43:8 | b [inner, f, b_] |
328331
| complex.cpp:42:8:42:8 | b [inner, f, a_] | complex.cpp:42:10:42:14 | inner [f, a_] |
@@ -855,6 +858,10 @@ nodes
855858
| by_reference.cpp:135:27:135:27 | a | semmle.label | a |
856859
| by_reference.cpp:136:8:136:13 | pouter [a] | semmle.label | pouter [a] |
857860
| by_reference.cpp:136:16:136:16 | a | semmle.label | a |
861+
| by_reference.cpp:140:4:140:5 | pa [inner post update] | semmle.label | pa [inner post update] |
862+
| by_reference.cpp:140:16:140:25 | call to user_input | semmle.label | call to user_input |
863+
| by_reference.cpp:145:15:145:16 | ref arg & ... | semmle.label | ref arg & ... |
864+
| by_reference.cpp:146:8:146:8 | s | semmle.label | s |
858865
| complex.cpp:40:17:40:17 | b [inner, f, a_] | semmle.label | b [inner, f, a_] |
859866
| complex.cpp:40:17:40:17 | b [inner, f, b_] | semmle.label | b [inner, f, b_] |
860867
| complex.cpp:42:8:42:8 | b [inner, f, a_] | semmle.label | b [inner, f, a_] |
@@ -1117,6 +1124,7 @@ nodes
11171124
| by_reference.cpp:134:29:134:29 | a | by_reference.cpp:88:13:88:22 | call to user_input | by_reference.cpp:134:29:134:29 | a | a flows from $@ | by_reference.cpp:88:13:88:22 | call to user_input | call to user_input |
11181125
| by_reference.cpp:135:27:135:27 | a | by_reference.cpp:88:13:88:22 | call to user_input | by_reference.cpp:135:27:135:27 | a | a flows from $@ | by_reference.cpp:88:13:88:22 | call to user_input | call to user_input |
11191126
| by_reference.cpp:136:16:136:16 | a | by_reference.cpp:96:8:96:17 | call to user_input | by_reference.cpp:136:16:136:16 | a | a flows from $@ | by_reference.cpp:96:8:96:17 | call to user_input | call to user_input |
1127+
| by_reference.cpp:146:8:146:8 | s | by_reference.cpp:140:16:140:25 | call to user_input | by_reference.cpp:146:8:146:8 | s | s flows from $@ | by_reference.cpp:140:16:140:25 | call to user_input | call to user_input |
11201128
| complex.cpp:42:18:42:18 | call to a | complex.cpp:53:19:53:28 | call to user_input | complex.cpp:42:18:42:18 | call to a | call to a flows from $@ | complex.cpp:53:19:53:28 | call to user_input | call to user_input |
11211129
| complex.cpp:42:18:42:18 | call to a | complex.cpp:55:19:55:28 | call to user_input | complex.cpp:42:18:42:18 | call to a | call to a flows from $@ | complex.cpp:55:19:55:28 | call to user_input | call to user_input |
11221130
| complex.cpp:43:18:43:18 | call to b | complex.cpp:54:19:54:28 | call to user_input | complex.cpp:43:18:43:18 | call to b | call to b flows from $@ | complex.cpp:54:19:54:28 | call to user_input | call to user_input |

0 commit comments

Comments
 (0)