From 18b267fd0a3c56d7372adae181109e7f0c988e4f Mon Sep 17 00:00:00 2001 From: Guillaume Francqueville Date: Fri, 17 Jun 2022 20:19:43 +0200 Subject: [PATCH] fix: panic on json encoding using json output sometimes trigger a panic, issue seems to happen because a goroutine modify the output object while it is being encoded, adding a mutex solve the issue --- cmd/amass/enum.go | 2 ++ requests/request.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/cmd/amass/enum.go b/cmd/amass/enum.go index a2f0cc799..30ef1e47b 100644 --- a/cmd/amass/enum.go +++ b/cmd/amass/enum.go @@ -523,6 +523,8 @@ func saveJSONOutput(e *enum.Enumeration, args *enumArgs, output chan *requests.O // Save all the output returned by the enumeration for out := range output { // Handle encoding the result as JSON + out.Mu.Lock() + defer out.Mu.Unlock() _ = enc.Encode(out) } } diff --git a/requests/request.go b/requests/request.go index 8c748275b..a0f777193 100644 --- a/requests/request.go +++ b/requests/request.go @@ -8,6 +8,7 @@ import ( "net" "strings" "time" + "sync" amassdns "github.com/OWASP/Amass/v3/net/dns" "github.com/caffix/pipeline" @@ -288,6 +289,7 @@ type WhoisRequest struct { // Output contains all the output data for an enumerated DNS name. type Output struct { + Mu sync.Mutex Name string `json:"name"` Domain string `json:"domain"` Addresses []AddressInfo `json:"addresses"`