C++: Use fully converted expressions for cpp/use-after-free
and cpp/double-free
#14193
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In tests such as:
we were getting a FP because we didn't block flow at the write to
p
. The reason dataflow wasn't blocking this write was because we didn't use the result of the reference dereference as the source, but instead we were using the value of typeint*&
as the source (becauseasExpr
doesn't returnReferenceDereference
expressions since they're conversions).The fix is to actually pick the fully converted expression (i.e., the value of type
int*
) as the source for dataflow. SSA then correctly sees that the variable is reassigned, and the flow is blocked.Commit-by-commit review recommended:
cpp/use-after-free
andcpp/double-free
to use the fully converted expression. This commit accepts one regression caused byasConvertedExpr
never returning aParenthesisExpr
.LeapYear.qll
usesasConvertedExpr
instead ofasExpr
. The library really shouldn't deal with conversions since it looks like the rest of the library only handles unconverted expressionsLeapYear.qll
by the changing use ofasConvertedExpr
toasExpr
.