Skip to content

CPP: Fix type confusion in IncorrectPointerscaling.ql #644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions change-notes/1.20/analysis-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

| **Query** | **Expected impact** | **Change** |
|----------------------------|------------------------|------------------------------------------------------------------|
| 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. |
| Unused static variable (`cpp/unused-static-variable`) | Fewer false positive results | Variables with the attribute `unused` are now excluded from the query. |

## Changes to QL libraries
2 changes: 1 addition & 1 deletion cpp/ql/src/Security/CWE/CWE-468/IncorrectPointerScaling.ql
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ private Type baseType(Type t) {
)
// Make sure that the type has a size and that it isn't ambiguous.
and strictcount(result.getSize()) = 1

}

/**
Expand Down Expand Up @@ -98,6 +97,7 @@ predicate defSourceType(SsaDefinition def, LocalScopeVariable v,
| p = v and
def.definedByParameter(p) and
sourceType = p.getType().getUnspecifiedType() and
strictcount(p.getType()) = 1 and
isPointerType(sourceType) and
sourceLoc = p.getLocation())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ predicate defSourceType(SsaDefinition def, LocalScopeVariable v,
| p = v and
def.definedByParameter(p) and
sourceType = p.getType().getUnspecifiedType() and
strictcount(p.getType()) = 1 and
isPointerType(sourceType) and
sourceLoc = p.getLocation())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ predicate defSourceType(SsaDefinition def, LocalScopeVariable v,
| p = v and
def.definedByParameter(p) and
sourceType = p.getType().getUnspecifiedType() and
strictcount(p.getType()) = 1 and
isPointerType(sourceType) and
sourceLoc = p.getLocation())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

struct MyStruct
{
int x, y, z, w;
};

void test(MyStruct *ptr)
{
MyStruct *new_ptr = ptr + 1; // GOOD
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// note the two different `MyStruct` definitions, in test_small.cpp and test_large.cpp. These are
// in different translation units and we assume they are never linked into the same program (which
// would result in undefined behaviour).

struct MyStruct
{
int x, y;
};

void test(MyStruct *ptr)
{
MyStruct *new_ptr = ptr + 1; // GOOD
}