File tree Expand file tree Collapse file tree 4 files changed +19
-16
lines changed
lib/semmle/code/cpp/ir/dataflow
src/Likely Bugs/Memory Management
test/query-tests/Security/CWE/CWE-457/semmle/tests Expand file tree Collapse file tree 4 files changed +19
-16
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ abstract class MustFlowConfiguration extends string {
3131 */
3232 abstract predicate isSink ( Operand sink ) ;
3333
34+ predicate isBarrier ( Instruction instr ) { none ( ) }
35+
3436 /**
3537 * Holds if the additional flow step from `node1` to `node2` must be taken
3638 * into account in the analysis.
@@ -55,11 +57,14 @@ abstract class MustFlowConfiguration extends string {
5557/** Holds if `node` flows from a source. */
5658pragma [ nomagic]
5759private predicate flowsFromSource ( Instruction node , MustFlowConfiguration config ) {
58- config .isSource ( node )
59- or
60- exists ( Instruction mid |
61- step ( mid , node , config ) and
62- flowsFromSource ( mid , pragma [ only_bind_into ] ( config ) )
60+ not config .isBarrier ( node ) and
61+ (
62+ config .isSource ( node )
63+ or
64+ exists ( Instruction mid |
65+ step ( mid , node , config ) and
66+ flowsFromSource ( mid , pragma [ only_bind_into ] ( config ) )
67+ )
6368 )
6469}
6570
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ class MustFlow extends MustFlowConfiguration {
7777 override predicate isSink ( Operand sink ) { isSinkImpl ( sink .getDef ( ) , _) }
7878
7979 override predicate allowInterproceduralFlow ( ) { none ( ) }
80+
81+ override predicate isBarrier ( Instruction instr ) { instr instanceof ChiInstruction }
8082}
8183
8284from
Original file line number Diff line number Diff line change 11| test.cpp:12:6:12:8 | foo | The variable $@ may not be initialized at this access. | test.cpp:11:6:11:8 | foo | foo |
22| test.cpp:113:6:113:8 | foo | The variable $@ may not be initialized at this access. | test.cpp:111:6:111:8 | foo | foo |
3- | test.cpp:121:6:121:8 | foo | The variable $@ may not be initialized at this access. | test.cpp:119:6:119:8 | foo | foo |
4- | test.cpp:179:7:179:9 | foo | The variable $@ may not be initialized at this access. | test.cpp:177:7:177:9 | foo | foo |
5- | test.cpp:192:7:192:9 | foo | The variable $@ may not be initialized at this access. | test.cpp:190:7:190:9 | foo | foo |
6- | test.cpp:213:7:213:7 | x | The variable $@ may not be initialized at this access. | test.cpp:211:7:211:7 | x | x |
73| test.cpp:219:3:219:3 | x | The variable $@ may not be initialized at this access. | test.cpp:218:7:218:7 | x | x |
84| test.cpp:243:13:243:13 | i | The variable $@ may not be initialized at this access. | test.cpp:241:6:241:6 | i | i |
95| test.cpp:336:10:336:10 | a | The variable $@ may not be initialized at this access. | test.cpp:333:7:333:7 | a | a |
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ void test4(bool b) {
2727 if (b) {
2828 foo = 1 ;
2929 }
30- use (foo); // BAD
30+ use (foo); // BAD [NOT DETECTED]
3131}
3232
3333void test5 () {
@@ -43,7 +43,7 @@ void test5(int count) {
4343 for (int i = 0 ; i < count; i++) {
4444 foo = i;
4545 }
46- use (foo); // BAD
46+ use (foo); // BAD [NOT DETECTED]
4747}
4848
4949void test6 (bool b) {
@@ -52,7 +52,7 @@ void test6(bool b) {
5252 foo = 42 ;
5353 }
5454 if (b) {
55- use (foo); // GOOD (REPORTED, FP)
55+ use (foo); // GOOD
5656 }
5757}
5858
@@ -64,7 +64,7 @@ void test7(bool b) {
6464 set = true ;
6565 }
6666 if (set) {
67- use (foo); // GOOD (REPORTED, FP)
67+ use (foo); // GOOD
6868 }
6969}
7070
@@ -89,7 +89,7 @@ void test9(int count) {
8989 if (!set) {
9090 foo = 42 ;
9191 }
92- use (foo); // GOOD (REPORTED, FP)
92+ use (foo); // GOOD
9393}
9494
9595void test10 () {
@@ -129,7 +129,7 @@ int absWrong(int i) {
129129 } else if (i < 0 ) {
130130 j = -i;
131131 }
132- return j; // wrong: j may not be initialized before use
132+ return j; // wrong: j may not be initialized before use [NOT DETECTED]
133133}
134134
135135// Example from qhelp
@@ -326,7 +326,7 @@ int test28() {
326326 a = false ;
327327 c = false ;
328328 }
329- return val; // GOOD [FALSE POSITIVE]
329+ return val; // GOOD
330330}
331331
332332int test29 () {
You can’t perform that action at this time.
0 commit comments