switching to plugins
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
339b6145f9
commit
0f0ce2af37
5 changed files with 70 additions and 42 deletions
|
@ -13,21 +13,24 @@ func LoadPlugin(path string) (Fuzzer, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sym, err := p.Lookup("MyFuzzerFunc")
|
||||
sym, err := p.Lookup("NewFuzzer")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("LoadPlugin: %q", err)
|
||||
}
|
||||
mff, ok := sym.(Fuzzer)
|
||||
nf, ok := sym.(func() (Fuzzer, error))
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("plugin at %q did not provide a FuzzFunc named MyFuzzerFunc", path)
|
||||
return nil, fmt.Errorf("LoadPlugin: plugin at %q did not provide a NewFuzzer function", path)
|
||||
}
|
||||
return mff, nil
|
||||
return nf()
|
||||
}
|
||||
|
||||
// NewFuzzer initializes a new Fuzzer
|
||||
type NewFuzzer func() (Fuzzer, error)
|
||||
|
||||
// Fuzzer is a struct that produces a FuzzFunc
|
||||
type Fuzzer interface {
|
||||
Name() string
|
||||
Func() FuzzFunc
|
||||
Func(path string, info os.FileInfo, timeout time.Duration) error
|
||||
}
|
||||
|
||||
// FuzzFunc is like filepath.WalkerFunc, but for poking at `path`
|
||||
|
|
42
walker/walkers/readFuzz/readFuzz.go
Normal file
42
walker/walkers/readFuzz/readFuzz.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue