llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Static analyzer false positive of Unix API violation: Improper use of 'open', when 'open' is in an alternative namespace

Open llvmbot opened this issue 10 years ago • 7 comments

Bugzilla Link 28331
Resolution FIXED
Resolved on Dec 20, 2016 00:00
Version 3.9
OS All
Attachments sample code demonstrating Unix API violation false positive
Reporter LLVM Bugzilla Contributor
CC @devincoughlin,@jefftrull,@xiangzhai

Extended Description

When the function open() appears in an alternative namespace with an unusual number of arguments, the static analyzer still reports it as a violation of the standard Unix function open().

This behavior occurs in checker-278: clang version 3.8.0 (tags/checker/checker-278) Target: x86_64-apple-darwin15.2.0

Apple Clang: Apple LLVM version 7.0.2 (clang-700.1.81) Target: x86_64-apple-darwin15.2.0

and Ubuntu 16.04 Clang: clang version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) Target: x86_64-pc-linux-gnu

The attached code demonstrates this behavior with: ❯ clang++ --analyze main.cc
main.cc:17:3: warning: Call to 'open' with more than three arguments outer::inner::open(ofs_, "foo"); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated.

llvmbot avatar Jun 27 '16 17:06 llvmbot

Leslie, r290023 changed checkPreStmt to not call any of the check() methods when the function is defined inside a namespace.

Thanks for your patch! http://koji.isoft-linux.org/koji/buildinfo?buildID=4794 testcase: k3b v17.04.0 works for me ;-)

Regards, Leslie Zhai

xiangzhai avatar Dec 20 '16 08:12 xiangzhai

Thanks for the fix! Won't be able to test until after the New Year. I'll re-open if necessary.

llvmbot avatar Dec 19 '16 19:12 llvmbot

Leslie, r290023 changed checkPreStmt to not call any of the check() methods when the function is defined inside a namespace.

You can see just the changes in that commit at:

https://github.com/llvm-mirror/clang/commit/ac7583ae2b142a8e95a2150ef5f702eea6fee827

Or, using svn from the command line:

svn diff -c 290023

devincoughlin avatar Dec 19 '16 18:12 devincoughlin

This should be fixed in r290023.

Hi Devin,

svn diff -r 290023 > 290023.patch about 4512 lines patch, but I did NOT find how to prevent UnixAPIChecker::CheckOpen from UnixAPIChecker::checkPreStmt, please give me some advice, thanks a lot!

Regards, Leslie Zhai

xiangzhai avatar Dec 19 '16 05:12 xiangzhai

This should be fixed in r290023.

devincoughlin avatar Dec 17 '16 03:12 devincoughlin

The same story for KStandardAction::open, it is KDE some library's namespace!

xiangzhai avatar Dec 07 '16 10:12 xiangzhai

assigned to @tkremenek

llvmbot avatar Jun 27 '16 17:06 llvmbot