Skip to content

Commit 359b15b

Browse files
committed
C++: Fix FP by special-casing compound assignments in 'asExprInternal'.
1 parent ce28c9b commit 359b15b

File tree

3 files changed

+2
-3
lines changed

3 files changed

+2
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,7 @@ module ExprFlowCached {
20692069
result = n.asExpr()
20702070
or
20712071
result = n.asDefinition() and
2072-
result instanceof CrementOperation
2072+
(result instanceof CrementOperation or result instanceof AssignOperation)
20732073
)
20742074
}
20752075

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/OverflowBuffer.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
| tests.cpp:577:7:577:13 | access to array | This array indexing operation accesses a negative index -1 on the $@. | tests.cpp:565:7:565:12 | buffer | array |
5050
| tests.cpp:637:6:637:15 | access to array | This array indexing operation accesses a negative index -1 on the $@. | tests.cpp:633:7:633:12 | buffer | array |
5151
| tests.cpp:645:7:645:13 | access to array | This array indexing operation accesses a negative index -1 on the $@. | tests.cpp:633:7:633:12 | buffer | array |
52-
| tests.cpp:654:6:654:12 | access to array | This array indexing operation accesses a negative index -1 on the $@. | tests.cpp:633:7:633:12 | buffer | array |
5352
| tests_restrict.c:12:2:12:7 | call to memcpy | This 'memcpy' operation accesses 2 bytes but the $@ is only 1 byte. | tests_restrict.c:7:6:7:13 | smallbuf | source buffer |
5453
| unions.cpp:26:2:26:7 | call to memset | This 'memset' operation accesses 200 bytes but the $@ is only 100 bytes. | unions.cpp:21:10:21:11 | mu | destination buffer |
5554
| unions.cpp:30:2:30:7 | call to memset | This 'memset' operation accesses 200 bytes but the $@ is only 100 bytes. | unions.cpp:15:7:15:11 | small | destination buffer |

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ void test26(bool cond)
651651
{
652652
ptr += 1;
653653
}
654-
if (ptr[-1] == 0) { return; } // GOOD: accesses buffer[1] [FALSE POSITIVE]
654+
if (ptr[-1] == 0) { return; } // GOOD: accesses buffer[1]
655655
}
656656

657657
int tests_main(int argc, char *argv[])

0 commit comments

Comments
 (0)