From 6ab86ff7e510b83279885ee7f407ecd32d3381c5 Mon Sep 17 00:00:00 2001 From: Yevgeny Pats Date: Sat, 5 Oct 2019 13:00:34 +0300 Subject: [PATCH] bugfix in mergedirectories for go-fuzz --- client/agent.go | 14 +++++++------- client/client.go | 2 +- client/utils.go | 18 +++++++++++++++--- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/client/agent.go b/client/agent.go index c2a163a..3793226 100644 --- a/client/agent.go +++ b/client/agent.go @@ -124,10 +124,8 @@ func (c *FuzzitClient) RunFuzzer(job Job, jobId string, updateDB bool) error { } } - if _, err := os.Stat("corpus"); os.IsNotExist(err) { - if err := os.Mkdir("corpus", 0644); err != nil { - return err - } + if err := createDirIfNotExist("corpus"); err != nil { + return err } if jobId != "" { @@ -137,9 +135,6 @@ func (c *FuzzitClient) RunFuzzer(job Job, jobId string, updateDB bool) error { } log.Println("downloading additional corpus") - if err := os.Mkdir("additional-corpus", 0644); err != nil { - return err - } if err := c.downloadAndExtract( "additional-corpus", fmt.Sprintf("orgs/%s/targets/%s/jobs/%s/additional-corpus", c.Org, c.currentJob.TargetId, c.jobId)); err != nil { @@ -149,6 +144,11 @@ func (c *FuzzitClient) RunFuzzer(job Job, jobId string, updateDB bool) error { return err } } + + if err := createDirIfNotExist("additional-corpus"); err != nil { + return err + } + } var err error diff --git a/client/client.go b/client/client.go index 1662d1f..9db8763 100644 --- a/client/client.go +++ b/client/client.go @@ -11,7 +11,7 @@ import ( ) const FuzzitEndpoint = "https://app.fuzzit.dev" -const Version = "v2.4.71" +const Version = "v2.4.72" type Target struct { Name string `firestore:"target_name"` diff --git a/client/utils.go b/client/utils.go index c590398..885ab9c 100644 --- a/client/utils.go +++ b/client/utils.go @@ -180,9 +180,12 @@ func mergeDirectories(dst string, src string) error { } if !info.IsDir() { fileName := info.Name() - err = os.Rename(filepath.Join(src, fileName), filepath.Join(dst, fileName)) - if err != nil { - return err + dstPath := filepath.Join(dst, fileName) + if _, err := os.Stat(path); os.IsNotExist(err) { + err = os.Rename(filepath.Join(src, fileName), dstPath) + if err != nil { + return err + } } } return nil @@ -190,3 +193,12 @@ func mergeDirectories(dst string, src string) error { return err } + +func createDirIfNotExist(path string) error { + if _, err := os.Stat(path); os.IsNotExist(err) { + if err := os.Mkdir(path, 0644); err != nil { + return err + } + } + return nil +}