Skip to content

Commit

Permalink
fix makefile cleanup, fix FuzzServer with Fuzz_FORKS
Browse files Browse the repository at this point in the history
Signed-off-by: Sepehrdad Sh <[email protected]>
  • Loading branch information
sepehrdaddev committed Nov 21, 2023
1 parent a49531f commit 0180de0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fuzz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ fuzz: $(FUZZ_TARGETS:=.out) ## run all fuzz tests
done

clean: ## clean temporary files and directories
$(RM) $(PREFIX)/*.out $(PREFIX)/*.h $(PREFIX)/main.*.go
$(RM) $(PREFIX)/*.out $(PREFIX)/*.a $(PREFIX)/*.h $(PREFIX)/main.*.go
30 changes: 27 additions & 3 deletions fuzz/fuzz_targets/FuzzServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@ import (
"github.com/zalando/skipper/config"
)

var initialized = false
var (
initialized = false
address = ""
)

func findAddress() (string, error) {
l, err := net.ListenTCP("tcp6", &net.TCPAddr{})

if err != nil {
return "", err
}

defer l.Close()

return l.Addr().String(), nil
}

func connect(host string) (net.Conn, error) {
for i := 0; i < 15; i++ {
conn, err := net.Dial("tcp", host)
conn, err := net.Dial("tcp6", host)

if err != nil {
continue
Expand All @@ -31,20 +46,29 @@ func connect(host string) (net.Conn, error) {

func FuzzServer(data []byte) int {
if !initialized {
addr, err := findAddress()

if err != nil {
log.Printf("failed to find address: %v\n", err)
return -1
}

cfg := config.NewConfig()
cfg.InlineRoutes = `r: * -> status(200) -> inlineContent("ok") -> <shunt>`
cfg.ApplicationLogLevel = logrus.PanicLevel
cfg.AccessLogDisabled = true
cfg.ApplicationLog = "/dev/null"
cfg.Address = addr

go func() {
log.Fatal(skipper.Run(cfg.ToOptions()))
}()

initialized = true
address = cfg.Address
}

conn, err := connect("localhost:9090")
conn, err := connect(address)

if err != nil {
log.Printf("failed to dial: %v\n", err)
Expand Down

0 comments on commit 0180de0

Please sign in to comment.