-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfuzz.go
More file actions
42 lines (33 loc) · 699 Bytes
/
fuzz.go
File metadata and controls
42 lines (33 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package php
import (
"bytes"
"os/exec"
)
// +build gofuzz
func Fuzz(data []byte) int {
interestingness := 0
isValid := validPHP(data)
if isValid {
interestingness++
}
p := NewParser()
p.Debug = true
_, err := p.Parse("test.php", string(data))
if err != nil {
interestingness++
}
if err == nil && !isValid {
panic("false negative: the input was invalid and not flagged")
} else if err != nil && isValid {
panic("false positive: the input was valid but flagged invalid")
}
return interestingness
}
func validPHP(data []byte) bool {
cmd := exec.Command("php", "-l")
cmd.Stdin = bytes.NewReader(data)
if err := cmd.Run(); err != nil {
return false
}
return true
}