Skip to content

Commit 0f268ca

Browse files
committed
CPP: Fix the issue.
1 parent 02a060f commit 0f268ca

File tree

4 files changed

+3
-7
lines changed

4 files changed

+3
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ private Type baseType(Type t) {
3434
)
3535
// Make sure that the type has a size and that it isn't ambiguous.
3636
and strictcount(result.getSize()) = 1
37-
3837
}
3938

4039
/**
@@ -98,6 +97,7 @@ predicate defSourceType(SsaDefinition def, LocalScopeVariable v,
9897
| p = v and
9998
def.definedByParameter(p) and
10099
sourceType = p.getType().getUnspecifiedType() and
100+
strictcount(p.getType()) = 1 and
101101
isPointerType(sourceType) and
102102
sourceLoc = p.getLocation())
103103
}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
| test.cpp:50:19:50:19 | p | This pointer might have type $@ (size 8), but the pointer arithmetic here is done with type int * (size 4). | test.cpp:45:11:45:11 | test.cpp:45:11:45:11 | double |
22
| test.cpp:94:18:94:18 | x | This pointer might have type $@ (size 4), but the pointer arithmetic here is done with type short * (size 2). | test.cpp:88:21:88:21 | test.cpp:88:21:88:21 | int |
33
| test.cpp:130:27:130:29 | arr | This pointer might have type $@ (size 4), but the pointer arithmetic here is done with type short * (size 2). | test.cpp:128:16:128:18 | test.cpp:128:16:128:18 | int |
4-
| test_large.cpp:9:22:9:24 | ptr | This pointer might have type $@ (size 8), but the pointer arithmetic here is done with type MyStruct * (size 16). | test_large.cpp:7:21:7:23 | test_large.cpp:7:21:7:23 | MyStruct |
5-
| test_large.cpp:9:22:9:24 | ptr | This pointer might have type $@ (size 8), but the pointer arithmetic here is done with type MyStruct * (size 16). | test_small.cpp:10:21:10:23 | test_small.cpp:10:21:10:23 | MyStruct |
6-
| test_small.cpp:12:22:12:24 | ptr | This pointer might have type $@ (size 16), but the pointer arithmetic here is done with type MyStruct * (size 8). | test_large.cpp:7:21:7:23 | test_large.cpp:7:21:7:23 | MyStruct |
7-
| test_small.cpp:12:22:12:24 | ptr | This pointer might have type $@ (size 16), but the pointer arithmetic here is done with type MyStruct * (size 8). | test_small.cpp:10:21:10:23 | test_small.cpp:10:21:10:23 | MyStruct |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ struct MyStruct
66

77
void test(MyStruct *ptr)
88
{
9-
MyStruct *new_ptr = ptr + 1; // GOOD [FALSE POSITIVE]
9+
MyStruct *new_ptr = ptr + 1; // GOOD
1010
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ struct MyStruct
99

1010
void test(MyStruct *ptr)
1111
{
12-
MyStruct *new_ptr = ptr + 1; // GOOD [FALSE POSITIVE]
12+
MyStruct *new_ptr = ptr + 1; // GOOD
1313
}

0 commit comments

Comments
 (0)