Skip to content

Commit 1f73834

Browse files
authored
Merge pull request #644 from geoffw0/pointerscaling
CPP: Fix type confusion in IncorrectPointerscaling.ql
2 parents 6ef16bb + 9857a85 commit 1f73834

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-1
lines changed

change-notes/1.20/analysis-cpp.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
| **Query** | **Expected impact** | **Change** |
1313
|----------------------------|------------------------|------------------------------------------------------------------|
14+
| Suspicious pointer scaling (`cpp/suspicious-pointer-scaling`) | Fewer false positives | False positives involving types that are not uniquely named in the snapshot have been fixed. |
1415
| Unused static variable (`cpp/unused-static-variable`) | Fewer false positive results | Variables with the attribute `unused` are now excluded from the query. |
1516

1617
## Changes to QL libraries

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

+1-1
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
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ predicate defSourceType(SsaDefinition def, LocalScopeVariable v,
8989
| p = v and
9090
def.definedByParameter(p) and
9191
sourceType = p.getType().getUnspecifiedType() and
92+
strictcount(p.getType()) = 1 and
9293
isPointerType(sourceType) and
9394
sourceLoc = p.getLocation())
9495
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ predicate defSourceType(SsaDefinition def, LocalScopeVariable v,
8989
| p = v and
9090
def.definedByParameter(p) and
9191
sourceType = p.getType().getUnspecifiedType() and
92+
strictcount(p.getType()) = 1 and
9293
isPointerType(sourceType) and
9394
sourceLoc = p.getLocation())
9495
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
struct MyStruct
3+
{
4+
int x, y, z, w;
5+
};
6+
7+
void test(MyStruct *ptr)
8+
{
9+
MyStruct *new_ptr = ptr + 1; // GOOD
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// note the two different `MyStruct` definitions, in test_small.cpp and test_large.cpp. These are
2+
// in different translation units and we assume they are never linked into the same program (which
3+
// would result in undefined behaviour).
4+
5+
struct MyStruct
6+
{
7+
int x, y;
8+
};
9+
10+
void test(MyStruct *ptr)
11+
{
12+
MyStruct *new_ptr = ptr + 1; // GOOD
13+
}

0 commit comments

Comments
 (0)