Flawfinder PDF
Flawfinder PDF
If the source code is in a subdirectory named xyzzy, you would probably start by opening a text window
and using flawfinder’s default settings, to analyze the program and report a prioritized list of potential secu-
rity vulnerabilities (the ‘‘less’’ just makes sure the results stay on the screen):
flawfinder xyzzy | less
At this point, you will a large number of entries; each entry begins with a filename, a colon, a line number,
a risk level in brackets (where 5 is the most risky), a category, the name of the function, and a description of
why flawfinder thinks the line is a vulnerability. Flawfinder normally sorts by risk level, showing the riski-
est items first; if you have limited time, it’s probably best to start working on the riskiest items and continue
until you run out of time. If you want to limit the display to risks with only a certain risk level or higher,
use the −−minlevel option. If you’re getting an extraordinary number of false positives because variable
names look like dangerous function names, use the −F option to remove reports about them. If you don’t
understand the error message, please see documents such as the Writing Secure Programs for Linux and
Unix HOWTO at http://www.dwheeler.com/secure-programs which provides more information on writing
secure programs.
Once you identify the problem and understand it, you can fix it. Occasionally you may want to re-do the
analysis, both because the line numbers will change and to make sure that the new code doesn’t introduce
yet a different vulnerability.
If you’ve determined that some line isn’t really a problem, and you’re sure of it, you can insert just before
or on the offending line a comment like
/* Flawfinder: ignore */
Once you’ve done that, you should go back and search for the program’s inputs, to make sure that the pro-
gram strongly filters any of its untrusted inputs. Flawfinder can identify many program inputs by using the
−−inputs option, like this:
flawfinder −−inputs xyzzy
Flawfinder can integrate well with text editors and integrated development environments; see the examples
for more information.
Flawfinder includes many other options, including ones to create HTML versions of the output (useful for
prettier displays). The next section describes those options in more detail.
OPTIONS
Flawfinder has a number of options, which can be grouped into options that control its own documentation,
select which hits to display, select the output format, and perform hitlist management.
Documentation
−−help Show usage (help) information.
−−inputs
−I Show only functions that obtain data from outside the program; this also sets minlevel to 0.
−−minlevel=X
-m X Set minimum risk level to X for inclusion in hitlist. This can be from 0 (‘‘no risk’’) to 5
(‘‘maximum risk’’); the default is 1.
−−falsepositive
−F Do not include hits that are likely to be false positives. Currently, this means that function
names are ignored if they’re not followed by "(", and that declarations of character arrays
aren’t noted. Thus, if you have use a variable named "access" everywhere, this will elimi-
nate references to this ordinary variable. This isn’t the default, because this also increases
the likelihood of missing important hits; in particular, function names in #define clauses and
calls through function pointers will be missed.
−−context
−c Show context, i.e., the line having the "hit"/potential flaw. By default the line is shown
immediately after the warning.
−−dataonly
−D Don’t display the header and footer. Use this along with −−quiet to see just the data itself.
−−immediate
-i Immediately display hits (don’t just wait until the end).
−−singleline
-S Display as single line of text output for each hit. Useful for interacting with compilation
tools.
−−omittime Omit timing information. This is useful for regression tests of flawfinder itself, so that the
output doesn’t vary depending on how long the analysis takes.
−−quiet
−Q Don’t display status information (i.e., which files are being examined) while the analysis is
going on.
Hitlist Management
−−savehitlist=F
Save all resulting hits (the "hitlist") to F.
−−loadhitlist=F
Load the hitlist from F instead of analyzing source programs.
−−diffhitlist=F
Show only hits (loaded or analyzed) not in F. F was presumably created previously using
−−savehitlist. If the −−loadhitlist option is not provided, this will show the hits in the ana-
lyzed source code files that were not previously stored in F. If used along with −−loadhitlist,
EXAMPLES
Here are various examples of how to invoke flawfinder. The first examples show various simple command-
line options. Flawfinder is designed to work well with text editors and integrated development environ-
ments, so the next sections show how to integrate flawfinder into vim and emacs.
flawfinder −−minlevel=4 .
Examine all the C/C++ files in the current directory and its subdirectories (recursively); only
report vulnerabilities level 4 and up (the two highest risk levels).
You can now use various editing commands to view the results. The command ":cn" displays the next hit;
":cN" displays the previous hit, and ":cr" rewinds back to the first hit. ":copen" will open a window to show
the current list of hits, called the "quickfix window"; ":cclose" will close the quickfix window. If the buffer
in the used window has changed, and the error is in another file, jumping to the error will fail. You have to
make sure the window contains a buffer which can be abandoned before trying to jump to a new file, say by
saving the file; this prevents accidental data loss.
BUGS
Flawfinder is currently limited to C/C++. It’s designed so that adding support for other languages should
be easy.
Flawfinder can be fooled by user-defined functions or method names that happen to be the same as those
defined as ‘‘hits’’ in its database, and will often trigger on definitions (as well as uses) of functions with the
same name. This is because flawfinder is based on text pattern matching, which is part of its fundamental
design and not easily changed. This isn’t as much of a problem for C code, but it can be more of a problem
for some C++ code which heavily uses classes and namespaces. On the positive side, flawfinder doesn’t get
confused by many complicated preprocessor sequences that other tools sometimes choke on. Also, having
the same name as a common library routine name can indicate that the developer is simply rewriting a com-
mon library routine, say for portability’s sake. Thus, there are reasonable odds that these rewritten routines
will be vulnerable to the same kinds of misuse. The −−falsepositive option can help somewhat. If this is a
serious problem, feel free to modify the program, or process the flawfinder output through other tools to
remove the false positives.
Preprocessor commands embedded in the middle of a parameter list of a call can cause problems in parsing,
in particular, if a string is opened and then closed multiple times using an #ifdef .. #else construct,
flawfinder gets confused. Such constructs are bad style, and will confuse many other tools too. If you must
analyze such files, rewrite those lines. Thankfully, these are quite rare.
The routine to detect statically defined character arrays uses simple text matching; some complicated expre-
sions can cause it to trigger or not trigger unexpectedly.
Flawfinder looks for specific patterns known to be common mistakes. Flawfinder (or any tool like it) is not
SEE ALSO
See the flawfinder website at http://www.dwheeler.com/flawfinder. You should also see the Secure Pro-
gramming for Unix and Linux HOWTO at http://www.dwheeler.com/secure-programs.
AUTHOR
David A. Wheeler ([email protected]).