fuzz-walker/main.go
Vincent Batts c8893f8f46
Initial commit
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2018-05-30 13:28:42 -04:00

82 lines
1.6 KiB
Go

package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/sirupsen/logrus"
)
var (
dirs = []string{"/sys", "/proc"}
fuzzes = map[string]FuzzFunc{
"chmod": chmodFuzz,
"read": readFuzz,
"writeBytes": writeBytesFuzz,
"writeNum": writeNumFuzz,
}
fuzzTimeout = 500 * time.Millisecond
)
func main() {
for _, dir := range dirs {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.Mode().IsRegular() {
return nil
}
for fname, fuzz := range fuzzes {
if err := fuzz(path, info, fuzzTimeout); err != nil {
logrus.Warnf("%s: %q fuzz failed with: %v", path, fname, err)
}
}
return nil
})
if err != nil {
logrus.Warnf("%s: %v", dir, err)
}
}
}
type FuzzFunc func(path string, info os.FileInfo, timeout time.Duration) error
func readFuzz(path string, info os.FileInfo, timeout time.Duration) error {
c1 := make(chan error, 1)
go func() {
fd, err := os.Open(path)
if err != nil {
c1 <- err
}
defer fd.Close()
_, err = io.Copy(ioutil.Discard, fd)
c1 <- err
}()
select {
case err := <-c1:
return err
case <-time.After(timeout):
return fmt.Errorf("timeout reached")
}
return nil
}
func writeNumFuzz(path string, info os.FileInfo, timeout time.Duration) error {
return nil
}
func writeBytesFuzz(path string, info os.FileInfo, timeout time.Duration) error {
return nil
}
func chmodFuzz(path string, info os.FileInfo, timeout time.Duration) error {
return nil
}
// maybe have an ioctl fuzzer