]> granicus.if.org Git - clang/commit
[analyzer] Handle the M_ZERO and __GFP_ZERO flags in kernel mallocs.
authorJordan Rose <jordan_rose@apple.com>
Wed, 26 Mar 2014 17:05:46 +0000 (17:05 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 26 Mar 2014 17:05:46 +0000 (17:05 +0000)
commit447549aa0bae6fe171214e1fcd8f330ff87aa9b0
treef5d167d9b79916c29a3afa011b29b4b9f9e90215
parent972fd1d7f0289d95dd78c64a424f130be44ecffe
[analyzer] Handle the M_ZERO and __GFP_ZERO flags in kernel mallocs.

Add M_ZERO awareness to malloc() static analysis in Clang for FreeBSD,
NetBSD, and OpenBSD in a similar fashion to O_CREAT for open(2).
These systems have a three-argument malloc() in the kernel where the
third argument contains flags; the M_ZERO flag will zero-initialize the
allocated buffer.

This should reduce the number of false positives when running static
analysis on BSD kernels.

Additionally, add kmalloc() (Linux kernel malloc()) and treat __GFP_ZERO
like M_ZERO on Linux.

Future work involves a better method of checking for named flags without
hardcoding values.

Patch by Conrad Meyer, with minor modifications by me.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204832 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/MallocChecker.cpp
lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
test/Analysis/kmalloc-linux.c [new file with mode: 0644]
test/Analysis/malloc-three-arg.c [new file with mode: 0644]