Skip to content
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

C++: Fix FPs to cpp/return-stack-allocated-memory #18309

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class ReturnStackAllocatedMemoryConfig extends MustFlowConfiguration {
or
node2.(PointerOffsetInstruction).getLeftOperand() = node1
}

override predicate isBarrier(Instruction n) { n.getResultType() instanceof ErroneousType }
}

from
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The "Returning stack-allocated memory" query (`cpp/return-stack-allocated-memory`) no longer produces results if there is an extraction error in the returned expression.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// semmle-extractor-options: -std=c++14
// semmle-extractor-options: -std=c++14 --expect_errors
class MyClass
calumgrant marked this conversation as resolved.
Show resolved Hide resolved
{
public:
Expand Down Expand Up @@ -248,4 +248,5 @@ char* test_strdupa(const char* s) {
void* test_strndupa(const char* s, size_t size) {
char* s2 = strndupa(s, size);
return s2; // BAD
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// semmle-extractor-options: --expect_errors

UNKNOWN_TYPE test_error_value() {
UNKNOWN_TYPE x;
return x; // GOOD: Error return type
}

void* test_error_pointer() {
UNKNOWN_TYPE x;
return &x; // GOOD: Don't know what &x means
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is "BAD" (I guess unless & is actually an overloaded operator, because who knows in that case), because we're taking the address of a local variable.

I'm fine with silencing these, but the comment needs to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, they are "probably" bad. Do we even need a comment?

Suggested change
return &x; // GOOD: Don't know what &x means
return &x; // BAD [FALSE NEGATIVE]: &x is an error

vs.

Suggested change
return &x; // GOOD: Don't know what &x means
return &x; // BAD [FALSE NEGATIVE]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just // BAD [FALSE NEGATIVE] is sufficient in both cases, I think.

}

int* test_error_pointer_member() {
UNKNOWN_TYPE x;
return &x.y; // GOOD: Don't know what x.y means
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

}
Loading