Skip to content

Commit 8623d8e

Browse files
committed
C++: Exclude unevaluated expressions from BufferAccess.
1 parent b37bb66 commit 8623d8e

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

cpp/ql/lib/semmle/code/cpp/security/BufferAccess.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ int getPointedSize(Type t) {
1414
* BufferWrite differ.
1515
*/
1616
abstract class BufferAccess extends Expr {
17+
BufferAccess() { not this.isUnevaluated() }
18+
1719
abstract string getName();
1820

1921
/**

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
@@ -50,7 +50,6 @@
5050
| tests.cpp:546:6:546:10 | call to fread | This 'fread' operation may access 400 bytes but the $@ is only 100 bytes. | tests.cpp:532:7:532:16 | charBuffer | destination buffer |
5151
| tests.cpp:569:6:569:15 | access to array | This array indexing operation accesses a negative index -1 on the $@. | tests.cpp:565:7:565:12 | buffer | array |
5252
| 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 |
53-
| tests.cpp:608:33:608:43 | access to array | This array indexing operation accesses byte offset 101 but the $@ is only 100 bytes. | tests.cpp:607:7:607:12 | buffer | array |
5453
| 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 |
5554
| 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 |
5655
| unions.cpp:27:2:27:7 | call to memset | This 'memset' operation accesses 100 bytes but the $@ is only 10 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
@@ -605,7 +605,7 @@ void test22(bool b, const char* source) {
605605

606606
int test23() {
607607
char buffer[100];
608-
return sizeof(buffer) / sizeof(buffer[101]); // GOOD [FALSE POSITIVE]
608+
return sizeof(buffer) / sizeof(buffer[101]); // GOOD
609609
}
610610

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

0 commit comments

Comments
 (0)