-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegers.go
More file actions
52 lines (46 loc) · 1.09 KB
/
Copy pathintegers.go
File metadata and controls
52 lines (46 loc) · 1.09 KB
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
43
44
45
46
47
48
49
50
51
52
package sonar
import (
"encoding/binary"
"strconv"
)
func findInt(i int) {
if 1337 == i {
panic("Found int")
}
}
// FuzzIntegerBigEndian shows how sonar can discover integers to use as inputs to increase coverage
func FuzzIntegerBigEndian(data []byte) int {
// interpret data as big-endian encoded
if len(data) < 8 {
return 0
}
findInt(int(binary.BigEndian.Uint64(data)))
return 1
}
// FuzzIntegerLittleEndian shows how sonar can discover integers to use as inputs to increase coverage
func FuzzIntegerLittleEndian(data []byte) int {
// interpret data as little-endian encoded
if len(data) < 8 {
return 0
}
findInt(int(binary.LittleEndian.Uint64(data)))
return 1
}
// FuzzIntegerDecimalString interprets input as a decimal string
func FuzzIntegerDecimalString(data []byte) int {
i, err := strconv.Atoi(string(data))
if err != nil {
return 0
}
findInt(i)
return 1
}
// FuzzIntegerHexString interprets input as a hexadecimal string
func FuzzIntegerHexString(data []byte) int {
i, err := strconv.ParseInt(string(data), 16, 64)
if err != nil {
return 0
}
findInt(int(i))
return 1
}