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 {
31
31
*/
32
32
abstract predicate isSink ( Operand sink ) ;
33
33
34
+ predicate isBarrier ( Instruction instr ) { none ( ) }
35
+
34
36
/**
35
37
* Holds if the additional flow step from `node1` to `node2` must be taken
36
38
* into account in the analysis.
@@ -55,11 +57,14 @@ abstract class MustFlowConfiguration extends string {
55
57
/** Holds if `node` flows from a source. */
56
58
pragma [ nomagic]
57
59
private 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
+ )
63
68
)
64
69
}
65
70
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ class MustFlow extends MustFlowConfiguration {
77
77
override predicate isSink ( Operand sink ) { isSinkImpl ( sink .getDef ( ) , _) }
78
78
79
79
override predicate allowInterproceduralFlow ( ) { none ( ) }
80
+
81
+ override predicate isBarrier ( Instruction instr ) { instr instanceof ChiInstruction }
80
82
}
81
83
82
84
from
Original file line number Diff line number Diff line change 1
1
| test.cpp:12:6:12:8 | foo | The variable $@ may not be initialized at this access. | test.cpp:11:6:11:8 | foo | foo |
2
2
| 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 |
7
3
| test.cpp:219:3:219:3 | x | The variable $@ may not be initialized at this access. | test.cpp:218:7:218:7 | x | x |
8
4
| test.cpp:243:13:243:13 | i | The variable $@ may not be initialized at this access. | test.cpp:241:6:241:6 | i | i |
9
5
| 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) {
27
27
if (b) {
28
28
foo = 1 ;
29
29
}
30
- use (foo); // BAD
30
+ use (foo); // BAD [NOT DETECTED]
31
31
}
32
32
33
33
void test5 () {
@@ -43,7 +43,7 @@ void test5(int count) {
43
43
for (int i = 0 ; i < count; i++) {
44
44
foo = i;
45
45
}
46
- use (foo); // BAD
46
+ use (foo); // BAD [NOT DETECTED]
47
47
}
48
48
49
49
void test6 (bool b) {
@@ -52,7 +52,7 @@ void test6(bool b) {
52
52
foo = 42 ;
53
53
}
54
54
if (b) {
55
- use (foo); // GOOD (REPORTED, FP)
55
+ use (foo); // GOOD
56
56
}
57
57
}
58
58
@@ -64,7 +64,7 @@ void test7(bool b) {
64
64
set = true ;
65
65
}
66
66
if (set) {
67
- use (foo); // GOOD (REPORTED, FP)
67
+ use (foo); // GOOD
68
68
}
69
69
}
70
70
@@ -89,7 +89,7 @@ void test9(int count) {
89
89
if (!set) {
90
90
foo = 42 ;
91
91
}
92
- use (foo); // GOOD (REPORTED, FP)
92
+ use (foo); // GOOD
93
93
}
94
94
95
95
void test10 () {
@@ -129,7 +129,7 @@ int absWrong(int i) {
129
129
} else if (i < 0 ) {
130
130
j = -i;
131
131
}
132
- return j; // wrong: j may not be initialized before use
132
+ return j; // wrong: j may not be initialized before use [NOT DETECTED]
133
133
}
134
134
135
135
// Example from qhelp
@@ -326,7 +326,7 @@ int test28() {
326
326
a = false ;
327
327
c = false ;
328
328
}
329
- return val; // GOOD [FALSE POSITIVE]
329
+ return val; // GOOD
330
330
}
331
331
332
332
int test29 () {
You can’t perform that action at this time.
0 commit comments