Verification and Static Analysis: A Brief Overview
Verification and Static Analysis: A Brief Overview
A Brief Overview
Professor Mark Gabel Department of Computer Science University of Texas at Dallas
How do we know?
String s = if (s == null) { int count = s.indexOf(.); }
How do we know?
String s = // know nothing at this point // facts = {} if (s == null) { // know that s is null // facts = {s is null} // know that this call will fail! int count = s.indexOf(.); }
Practical Success
Verification (Software)
NASA/JPL: Mars Rovers (selected algorithms) Microsoft: Static Driver Verifier
Proves the absence of certain types of bugs in Windows drivers
Bug finding
Coverity
Grew from research at Stanford
FindBugs/Eclipse/IntelliJ
Lightweight analysis for bug patterns
Schema
String s = // know nothing at this point if (s == null) { // know that s is null // know that this call will fail! int count = s.indexOf(.); }
Program
Facts
Scope of Facts
Testing: we learn facts about one input at a time Static Analysis: we learn facts about all inputs at once
On every possible execution, x is null at line 9 This program never writes beyond the end of an array Every path from a user form to the database passes through a sanitizing function (security errors)
Exhaustiveness
Testing: can never prove the absence of bugs
(Except for exhaustive testing)
Static Analysis: can Don Knuth: Beware of bugs in the above code; I have only proved it correct, not tried it.
Incorrect assumptions invalidate results
Assuming single-threaded execution Assuming the lack of memory errors Assuming fault-free hardware
Precision
Testing: every bug you find is real
You can replicate it using a test case
Static analysis
Bugs and Errors may not be real
Dead code Flaws in reasoning, over-abstraction These are called False positives
A complete analysis:
Can be incorrect when it returns no errors/verified Will never report false positives: every bug it finds is real
Practicality
Sound tools can be highly noisy (most bugs are false) They often dont scale well
Problems
Loops Complex control flow Function calls and recursion Unconstrained input variables
12
An unsound and incomplete static analysis tool is often called a bug finding tool
Clarifies its intentions not trying to prove things correct Coverity, CodeSonar, IntelliJ Inspections, FindBugs
Strategy
Go after low hanging fruit: obvious bugs Increase analysis power until false positive rate is unacceptable
13
14
Other Applications
Static analysis technology can be used for other purposes, not just bug-finding or verification
Test case generation
Pick a line of code. Generate a test that will reach that line.
Static profiling
Research: how fast will your program run?
15
It has had some practical success and is improving constantly, but it is still far from being truly practical
One of the key motivating domains is security It will only improve
Bug-finding tools have had the highest industrial penetration across domains
You already used one in your project
16