Skip to content

Commit 0f794b5

Browse files
committed
C++: Fix the issue.
1 parent 2e987f8 commit 0f794b5

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

cpp/ql/src/Security/CWE/CWE-468/SuspiciousAddWithSizeof.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import IncorrectPointerScalingCommon
1818
private predicate isCharSzPtrExpr(Expr e) {
1919
exists(PointerType pt | pt = e.getFullyConverted().getUnspecifiedType() |
2020
pt.getBaseType() instanceof CharType or
21-
pt.getBaseType() instanceof VoidType
21+
pt.getBaseType() instanceof VoidType or
22+
pt.getBaseType() instanceof ErroneousType // this could be char / void type in a successful compilation
2223
)
2324
}
2425

cpp/ql/test/query-tests/Security/CWE/CWE-468/semmle/SuspiciousAddWithSizeof/SuspiciousAddWithSizeof.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
| buildless.cpp:5:15:5:25 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const short * | const short * |
22
| buildless.cpp:6:13:6:23 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const int * | const int * |
3-
| buildless.cpp:7:11:7:21 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const <error-type> * | const <error-type> * |
4-
| buildless.cpp:8:12:8:22 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const <error-type> * | const <error-type> * |
5-
| buildless.cpp:9:12:9:22 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const <error-type> * | const <error-type> * |
63
| test.cpp:6:30:6:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
74
| test.cpp:14:30:14:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
85
| test.cpp:22:25:22:35 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |

cpp/ql/test/query-tests/Security/CWE/CWE-468/semmle/SuspiciousAddWithSizeof/buildless.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ void test_buildless(const char *p_c, const short *p_short, const int *p_int, con
44
*(p_c + sizeof(int)); // GOOD (`sizeof(char)` is 1)
55
*(p_short + sizeof(int)); // BAD
66
*(p_int + sizeof(int)); // BAD
7-
*(p_8 + sizeof(int)); // GOOD (`sizeof(p_8)` is 1) [FALSE POSITIVE]
8-
*(p_16 + sizeof(int)); // BAD
9-
*(p_32 + sizeof(int)); // BAD
7+
*(p_8 + sizeof(int)); // GOOD (`sizeof(p_8)` is 1, but there's an error in the type)
8+
*(p_16 + sizeof(int)); // BAD [NOT DETECTED]
9+
*(p_32 + sizeof(int)); // BAD [NOT DETECTED]
1010
}

0 commit comments

Comments
 (0)