Skip to content

Commit e443eb8

Browse files
committed
CPP: Fix type logic.
1 parent c904a33 commit e443eb8

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import IncorrectPointerScalingCommon
1515

1616
private predicate isCharSzPtrExpr(Expr e) {
1717
exists (PointerType pt
18-
| pt = e.getFullyConverted().getUnderlyingType()
19-
| pt.getBaseType().getUnspecifiedType() instanceof CharType
20-
or pt.getBaseType().getUnspecifiedType() instanceof VoidType)
18+
| pt = e.getFullyConverted().getType().getUnspecifiedType()
19+
| pt.getBaseType() instanceof CharType
20+
or pt.getBaseType() instanceof VoidType)
2121
}
2222

2323
from Expr sizeofExpr, Expr e

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
| test.cpp:30:25:30:35 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is int *. |
55
| test.cpp:38:30:38:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is int *. |
66
| test.cpp:61:27:61:37 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is int *. |
7-
| test.cpp:88:35:88:47 | sizeof(MyABC) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is myChar *const. |
87
| test.cpp:89:40:89:52 | sizeof(MyABC) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is myInt *const. |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class MyTest8Class
8585
pairPtr((myChar *)malloc(sizeof(MyABC) * 2)),
8686
pairPtrInt((myInt *)malloc(sizeof(MyABC) * 2))
8787
{
88-
myChar *secondPtr = pairPtr + sizeof(MyABC); // GOOD [FALSE POSITIVE]
88+
myChar *secondPtr = pairPtr + sizeof(MyABC); // GOOD
8989
myInt *secondPtrInt = pairPtrInt + sizeof(MyABC); // BAD
9090
}
9191

0 commit comments

Comments
 (0)