Static analysis for PHP Static analysis is an emerging field, in particular in the PHP world. Reviewing source code at the speed of a computer requires powerful theoretical tools: control flow diagram, abstract syntactic trees, acyclic dependency graph. If all this seems far and remote from PHP, come and learn how they apply to your favorite language! We'll see how to combine all those aspects to build a useful auditing engine.
14. Play in the tree
Local patterns
$a = 1 + $b;
$a = $a + 1;
$z = $a + $b + $d - $b + $e;
Assignat
ion
$a Addition
LEFT RIGHT
$b
RIGHT
1
LEFT
Motif
Analyse
Analyse
19. Definitions and usage
Function definition
Parameters
Functioncall
Arguments
Context
foo($a)
DEFINITION
function
foo($b)
$a = 2 NEXT echo $a
Sequence
NEXT
BLOCK
20. Definitions and usage
Function definition
Parameters
Functioncall
Arguments
Context
foo($a[1])
DEFINITION
function
foo($b)
foo($b)
foo($a)
foo($a)
DEFINITION
DEFINITION
DEFINITION
21. Definitions and usage
Function definition
Parameters
Functioncall
Arguments
Context
foo($a[1])
DEFINITION
function
foo($b)
22. What is that?
One function call,
Multiple definition?
function
foo($b)
DEFINITION
foo($a)
function
foo($b)
function
foo($b)
function
foo($b)
DEFINITION
DEFINITION
DEFINITION
31. Dead Function (hardest)
Recursive, level 2
Recursive, level 3
Recursive, level 4…
DEFINITION
function
foob($b)
function
fooa($b)
DEFINITION
32. Dead Function (hardest)
Recursive, level 2
Recursive, level 3
Recursive, level 4…
DEFINITION
function
foob($b)
function
fooa($b)
DEFINITION
function
fooc($b)
DEFINITION
33. Dead functions
No call to the function
Function called by dead functions
Recursive functions
Level 2+ recursive functions
34. What fresh hell is that?
Call to function without
definition ?
bar($a)