-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: Fix some FPs in cpp/invalid-pointer-deref
#12961
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
base: main
Are you sure you want to change the base?
Conversation
… interesting pointer arithmetic operations.
8f784d8
to
e38f61d
Compare
Force-pushed a rebase to resolve the testcase conflicts after merging #12960. There are some lost results. I'll investigate if they are the FPs (and are represented well by our tests). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks sensible, but I have a very hard time understanding why this solves the referenced FPs. If I, for example, look at:
void test15(unsigned index) {
unsigned size = index + 13;
if(size < index) {
return;
}
int* newname = new int[size];
newname[index] = 0; // GOOD [FALSE POSITIVE]
}
There is exactly one PointerAdd
in the IR and that is used in a Store
. So it seems this should not be a case that is ruled out by this PR, yet the FP disappears.
iTo.(ConvertInstruction).getUnary() = iFrom or | ||
iTo.(CheckedConvertOrNullInstruction).getUnary() = iFrom or | ||
iTo.(InheritanceConversionInstruction).getUnary() = iFrom or | ||
// it's fine to treat pointer arithmetic as conversions as conversions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// it's fine to treat pointer arithmetic as conversions as conversions | |
// it's fine to treat pointer arithmetic as conversions |
But that PointerAdd is not flowing into the value of a store, instead, it's flowing into the store address 🙂. |
My understanding of what the query is supposed to do is that were are actually only interested in the addresses from with we load and store, so this only adds to my confusion. Why would we look at all at values being stored? |
After sleeping on this I realized that you're right, @jketema. The query really shouldn't need to deal with this. The motivation for this PR was to remove FPs like: void test15(unsigned index) {
unsigned size = index + 13;
if(size >= index) {
int* newname = new int[size];
newname[index] = 0; // GOOD [FALSE POSITIVE]
}
} like we discussed above, this FP is removed because I'll pull this PR into a draft state while we discuss how to solve this problem. |
This fixes the FPs I added in #12953. The query is designed to search for patterns such as:
but by marking any
PointerArithmeticInstruction
s as a sink (or rather: anything that upper bounds aPointerArithmeticInstruction
) we get too much flow (as illustrated in #12953). So this PR restricts the sinks to only thePointerArithmeticInstruction
such that:StoreInstruction
.