Skip to content

Commit 2ed54d5

Browse files
authored
Merge pull request #20040 from MathiasVP/fix-global-variable-recursion-fp
C++: Fix global variable dataflow FP
2 parents d33cd71 + c83895f commit 2ed54d5

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ private predicate isGlobalDefImpl(
153153
GlobalLikeVariable v, IRFunction f, int indirection, int indirectionIndex
154154
) {
155155
exists(VariableAddressInstruction vai |
156+
// The right-hand side of an initialization of a global variable
157+
// creates its own `IRFunction`. We don't want flow into that `IRFunction`
158+
// since the variable is only initialized once.
159+
not vai.getEnclosingFunction() = v and
156160
vai.getEnclosingIRFunction() = f and
157161
vai.getAstVariable() = v and
158162
isUse(_, _, vai, indirection, indirectionIndex) and

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ uniqueEnclosingCallable
66
| test.cpp:1126:33:1129:1 | {...} | Node should have one enclosing callable but has 0. |
77
| test.cpp:1127:3:1127:13 | reads_input | Node should have one enclosing callable but has 0. |
88
| test.cpp:1128:3:1128:21 | not_does_read_input | Node should have one enclosing callable but has 0. |
9+
| test.cpp:1158:18:1158:21 | call to sink | Node should have one enclosing callable but has 0. |
10+
| test.cpp:1158:18:1158:42 | ... , ... | Node should have one enclosing callable but has 0. |
11+
| test.cpp:1158:23:1158:31 | recursion | Node should have one enclosing callable but has 0. |
12+
| test.cpp:1158:35:1158:40 | call to source | Node should have one enclosing callable but has 0. |
913
uniqueCallEnclosingCallable
1014
| test.cpp:864:47:864:54 | call to source | Call should have one enclosing callable but has 0. |
1115
| test.cpp:872:46:872:51 | call to source | Call should have one enclosing callable but has 0. |
16+
| test.cpp:1158:18:1158:21 | call to sink | Call should have one enclosing callable but has 0. |
17+
| test.cpp:1158:35:1158:40 | call to source | Call should have one enclosing callable but has 0. |
1218
uniqueType
1319
uniqueNodeLocation
1420
missingLocation

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,4 +1153,6 @@ namespace conflation_regression {
11531153
*p = source(0);
11541154
read_deref_deref(p);
11551155
}
1156-
}
1156+
}
1157+
1158+
int recursion = (sink(recursion), source()); // clean

cpp/ql/test/query-tests/Security/CWE/CWE-134/semmle/consts/NonConstantFormat.expected

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
edges
2-
| consts.cpp:24:7:24:9 | **gv1 | consts.cpp:25:2:25:4 | *a | provenance | |
32
| consts.cpp:24:7:24:9 | **gv1 | consts.cpp:30:9:30:14 | *access to array | provenance | |
43
| consts.cpp:24:7:24:9 | **gv1 | consts.cpp:123:2:123:12 | *... = ... | provenance | |
5-
| consts.cpp:25:2:25:4 | *a | consts.cpp:26:2:26:4 | *{...} | provenance | |
6-
| consts.cpp:26:2:26:4 | *{...} | consts.cpp:24:7:24:9 | **gv1 | provenance | |
74
| consts.cpp:29:7:29:25 | **nonConstFuncToArray | consts.cpp:126:9:126:30 | *call to nonConstFuncToArray | provenance | |
85
| consts.cpp:30:9:30:14 | *access to array | consts.cpp:29:7:29:25 | **nonConstFuncToArray | provenance | |
96
| consts.cpp:85:7:85:8 | gets output argument | consts.cpp:86:9:86:10 | *v1 | provenance | |
@@ -38,8 +35,6 @@ edges
3835
| consts.cpp:144:16:144:18 | readStringRef output argument | consts.cpp:145:9:145:11 | *v12 | provenance | |
3936
nodes
4037
| consts.cpp:24:7:24:9 | **gv1 | semmle.label | **gv1 |
41-
| consts.cpp:25:2:25:4 | *a | semmle.label | *a |
42-
| consts.cpp:26:2:26:4 | *{...} | semmle.label | *{...} |
4338
| consts.cpp:29:7:29:25 | **nonConstFuncToArray | semmle.label | **nonConstFuncToArray |
4439
| consts.cpp:30:9:30:14 | *access to array | semmle.label | *access to array |
4540
| consts.cpp:85:7:85:8 | gets output argument | semmle.label | gets output argument |

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy