-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: Block summary flow through strdup
and friends
#15504
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++: Block summary flow through strdup
and friends
#15504
Conversation
cb4bfa6
to
6f5ed9a
Compare
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.
LGTM if the DCA result changes make sense.
One question: This seems to work for cases where the modification occurs at indirection index 1. If it would occur at a higher indirection index, this is not covered, is that a correct observation? If so, this is probably not super relevant, as we likely don't model functions that behave in this way and have more than 1 indirection.
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll
Outdated
Show resolved
Hide resolved
…e.qll Co-authored-by: Jeroen Ketema <[email protected]>
It actually does work perfectly fine for any indirection level. You're right in that we don't actually model any such strange function that modifies something two indirections away, but that should still Just Work. To test this out, I've:
The tests aren't pretty, but hopefully it should demonstrate that this isn't only working for indirection index 1 🤞 |
68007a0
to
439d3d2
Compare
I've looked at the lost results and they're all FPs which are now removed for the exact right reason 🎉 |
This PR fixes a TODO that I left in as part of #14799.
In the above PR we removed false flow in code like:
by teaching the C/C++ dataflow library to rule out certain flow steps that shouldn't be used when calculating summaries (i.e., there shouldn't be a summary from the indirection of the input argument to
modify_copy
to the output indirection ofmodify_copy
). The terminology I used was that the step from*p
tox
at// (1)
isn't "identity preserving".This PR extends this set of exclusion rules to also block flow when a modelled function isn't identity preserving. A common example that we've seen in many FPs is
strdup(str)
.To verify that a functions input -> output relation is identity preserving, we check that
*input -> *output
andinput -> output
both holds (i.e., not only does the function has flow from the indirection of the input to the indirection of the output, but it also has flow from the input pointer to the output pointer).