Skip to content

C++: Add some additional uncontrolled format string tests #11958

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 1 commit into from
Jan 23, 2023

Conversation

jketema
Copy link
Contributor

@jketema jketema commented Jan 23, 2023

These duplicate the i9 and i91 tests slightly earlier in the same file, but use an explicit if instead of the ternary operator.

These demonstrate that the missing results for the i9 and i91 tests on the use-use dataflow feature branch are not due to the use of the ternary operator. As these tests might be useful in general, this PR targets main.

These duplicate the `i9` and `i91` tests slightly earlier in the same file, but
use an explicit `if` instead of the ternary operator.
@jketema jketema requested a review from a team as a code owner January 23, 2023 10:56
@github-actions github-actions bot added the C++ label Jan 23, 2023
Comment on lines +173 to +185
{
char b[64];
char *bp = &b[0];
char *t;
if (0) {
t = 0;
} else {
t = bp;
}
memcpy(t, argv[1] + 1, 1);
printf(bp);
printWrapper(bp);
}
Copy link
Contributor

@MathiasVP MathiasVP Jan 23, 2023

Choose a reason for hiding this comment

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

Actually, I think the reason we don't catch these is because dataflow doesn't do a good job at alias analysis: We're never really good at catching flows like:

// establish alias between p and q
// p = source();
// sink(q);

since dataflow only considers paths starting at source and onwards. So that's probably why we don't catch the flow in this example.

With that said, these are some excellent testcases!

It would be relatively simple to get the simple cases of this: Since the IR does a proper must-alias analysis we could incorporate this information and have an SSA definition of p be an SSA definition of q when the IR can deduce that p and q alias. This, however, won't get us very far due to the shortcomings of the IR's alias analysis for dataflow (i.e., we'd really like to have a may-alias analysis for dataflow, but the IR implements a must-alias analysis).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They do work with def-use dataflow, so that's a bit "funny" to say the least.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think that's because the def-use dataflow does use the IR's alias analysis in some cases 🤔.

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 did not know that.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Let me double check this to make sure I'm not lying.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, there is a couple of cases of reliance on the IR alias analysis:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we have something similar in the case of use-use dataflow?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would certainly be good to make use of this information (hopefully in a more structured way than how we do it on main currently). https://github.com/github/codeql-c-team/issues/714 describes a(n old) version of this problem, but it should probably be updated to reflect the state of the use-use flow branch.

@jketema
Copy link
Contributor Author

jketema commented Jan 23, 2023

Merging this. Please don't let this stop anyone from continuing the above discussion.

@jketema jketema merged commit 05ecd2e into github:main Jan 23, 2023
@jketema jketema deleted the argv-if-tests branch January 23, 2023 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants