43 lines
652 B
Go
43 lines
652 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"io/ioutil"
|
||
|
"os"
|
||
|
"time"
|
||
|
|
||
|
"git.thisco.de/vbatts/fuzz-walker/walker"
|
||
|
)
|
||
|
|
||
|
func NewFuzzer() (walker.Fuzzer, error) {
|
||
|
return &myFuzzer{}, nil
|
||
|
}
|
||
|
|
||
|
type myFuzzer struct{}
|
||
|
|
||
|
func (mf myFuzzer) Name() string {
|
||
|
return "readFuzz"
|
||
|
}
|
||
|
|
||
|
func (mf myFuzzer) Func(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
|
||
|
}
|