This is an archive of the discontinued LLVM Phabricator instance.

[Fix][StaticAnalyzer] Bug 39792 - False positive on strcpy targeting struct member
ClosedPublic

Authored by Pierre-vh on Dec 3 2018, 10:19 AM.

Details

Summary

Fix for the bug n°39792: False positive on strcpy targeting struct member
Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=39792

I fixed it by replacing the use of dyn_cast by two isas to check if Target is a DeclRefExpr or a MemberExpr.
The removal of the DeclRef variable seems to be meaningless because the only place where the DeclRef variable was used is one line below, and it was used to call a method which is inherited from Expr.
Thus, replacing the only use of DeclRef by Target should have no effect.

I also added a small test for this bugfix in test/Analysis/security-syntax-checks.m

Note: I think we can completely remove the outer if (isa<DeclRefExpr>(Target) || isa<MemberExpr>(Target)), no? Why should we only allow DeclRefExprs to pass this check?

PS: This is my first contribution ever to CLang (or any other open source project), so I'm totally open to feedback, even if it's harsh.

Thank you for your attention!

Diff Detail

Repository
rL LLVM

Event Timeline

Pierre-vh created this revision.Dec 3 2018, 10:19 AM
george.karpenkov accepted this revision.Dec 3 2018, 10:52 AM

Thank you for the fix, but how far can the pattern matching go? Seems easy enough to think of cases not covered by the above.
In any case, the fix looks good.

This revision is now accepted and ready to land.Dec 3 2018, 10:52 AM

Thank you for the fix, but how far can the pattern matching go? Seems easy enough to think of cases not covered by the above.
In any case, the fix looks good.

Hey,

Sadly I'm not experienced enough to think of every case that should pass this check, so I limited myself to just fixing the bug.
Can't we totally remove the outer if so we allow every Target expression that has a ConstantArrayType to pass this check?

Thank you for your time!

MTC added a subscriber: MTC.Dec 4 2018, 4:10 AM

Please add more context using the -U option, like git diff -U99999 ....

Sadly I'm not experienced enough to think of every case that should pass this check, so I limited myself to just fixing the bug.
Can't we totally remove the outer if so we allow every Target expression that has a ConstantArrayType to pass this check?

IMHO, it's fine to remove the outer check!

MTC accepted this revision.Dec 4 2018, 4:11 AM
Pierre-vh updated this revision to Diff 176661.Dec 4 2018, 9:59 AM

Hello again! I updated the diff and completely removed the outer if. Please let me know what you think!

Szelethus added a comment.EditedDec 4 2018, 10:40 AM

Thanks for the fix! :)

*deleted rest of the comment after re-reading the code*

lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
662 ↗(On Diff #176661)

No need for this newline.

Pierre-vh updated this revision to Diff 176676.Dec 4 2018, 10:56 AM

Here's the diff without the extra newline :)

Pierre-vh marked an inline comment as done.Dec 5 2018, 8:48 AM

Hi again!

As I'm quite new to this, I don't know what the next step is. Do we need to wait for more people to review this diff?
What happens when it's considered "ready"? How is it committed? (I don't have commit access)

Thank you for your help!

Szelethus added a comment.EditedDec 5 2018, 10:36 AM

I like what I'm seeing.

Hi again!

As I'm quite new to this, I don't know what the next step is. Do we need to wait for more people to review this diff?
What happens when it's considered "ready"? How is it committed? (I don't have commit access)

Welcome! :) Always great to see new people around.

Once the revision is accepted (and, preferably accepted by someone knowledgeable in the analyzer) you may commit. When you start contributing to the project, and you don't have commit access just yet, you should ask someone who does to commit the patch on your behalf. Once you have "enough" patches under your belt, you may ask for a commit access.

Here are some links with more info on patch reviews, commiting, and the like:

https://llvm.org/docs/Contributing.html
https://llvm.org/docs/DeveloperPolicy.html ("Making and Submitting a Patch" seems outdated, but the following sections are worth a read: "Code Reviews", "Obtaining Commit Access" (and the rest, if you have the time))
https://llvm.org/docs/Phabricator.html

Sadly, I won't be around my working PC for a while, so I can't commit on your behalf just yet. If you asked for someone to commit but no one did, it's perfectly fine to ping it once a week (or, more frequently if it's urgent).

Hello!

I'm pinging since it's been a week. If someone can commit this patch on my behalf, that would be great.

Thank you :)

Hello!

I'm trying one last ping since it's been a month and it hasn't been commited (I think).

Whoops, sorry. There were holidays, and then I did forget about this patch. I'll commit this now.

@Pierre-vh The patch does not compile due to unmatched braces. Please do test and compile before submitting!

This revision was automatically updated to reflect the committed changes.