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

CPP: Fix some use after free FPs. #14275

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

alexet
Copy link
Contributor

@alexet alexet commented Sep 20, 2023

We try and exclude source expressions that are frees themselves however if there are more than one expresssion for a node we may use one expression to detect it is a use but not eliminate it due to the other expression.

The dataflow node for a = b has two expressions (a = b and b). a = b is a function argument to an unknown function so we assume that it is used. b is not an argument to free. By using different expression we incorrectly work out that the node is a non-free use.

@github-actions github-actions bot added the C++ label Sep 20, 2023
@alexet alexet marked this pull request as ready for review September 26, 2023 16:55
@alexet alexet requested a review from a team as a code owner September 26, 2023 16:55
@alexet alexet added the no-change-note-required This PR does not need a change note label Sep 26, 2023
@jketema
Copy link
Contributor

jketema commented Sep 27, 2023

I'm wondering if this fix will still work after the frontend upgrade, because the IR (and the expressions yielded) will be different for these kinds of assignments these. Let me check that.

@jketema
Copy link
Contributor

jketema commented Sep 27, 2023

I'm wondering if this fix will still work after the frontend upgrade, because the IR (and the expressions yielded) will be different for these kinds of assignments these. Let me check that.

The fix still woks, but no longer seems needed after the frontend upgrade.

void test_free_malloc() {
void *a = malloc(10);
void *b;
free(b = a);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs some kind of // GOOD or // BAD comment. However, it's not clear to me to which query being tested here the comment applies.

@@ -31,7 +31,7 @@ private predicate externalCallNeverDereferences(FormattingFunctionCall call, int

predicate isUse0(DataFlow::Node n, Expr e) {
e = n.asExpr() and
not isFree(_, e, _) and
not isFree(n, _, _) and
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me a bit nervous. because isFree looks a (un)converted expressions explicitly. Was the change just made to bind n, or is there a deeper reason? If the former, can't we just drop the node argument of isUse0 completely?

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 think the change was leftover from an earlier attempt which I accidentality left in. I have now changed it to not have a DataFlow::Node argumebnt at all and call asExpr at call sites.

@jketema
Copy link
Contributor

jketema commented Sep 29, 2023

Thanks for the fixes. Your latest DCA experiment seemed to have failed hard. Would you mind kicking off a new one? Otherwise, this LGTM.

Kicked off a new DCA experiment myself.

Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

DCA LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants