From 91ebaa94149eacada6fedd51e460ef12c926c837 Mon Sep 17 00:00:00 2001 From: phillip-stephens Date: Wed, 6 May 2026 14:29:17 +1200 Subject: [PATCH 1/2] check annotation module output for null and replace with empty struct for downstream parsers --- annotate.go | 27 +++++++++++++++++++++++++-- censys.go | 1 - 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/annotate.go b/annotate.go index 0b80411..12e4d1d 100644 --- a/annotate.go +++ b/annotate.go @@ -19,6 +19,7 @@ import ( "encoding/csv" "fmt" "os/signal" + "reflect" "slices" "syscall" "time" @@ -246,6 +247,19 @@ func AnnotateWrite(path string, out <-chan string, wg *sync.WaitGroup) { log.Debug("write thread finished") } +func isPtrNil(i any) bool { + if i == nil { + return true + } + val := reflect.ValueOf(i) + switch val.Kind() { + case reflect.Ptr, reflect.Interface, reflect.Slice, reflect.Map: + return val.IsNil() + default: + return false + } +} + func AnnotateWorker(conf *GlobalConf, a Annotator, inChan <-chan inProcessIP, outChan chan<- inProcessIP, fieldName string, wg *sync.WaitGroup, i int) { name := a.GetFieldName() @@ -257,9 +271,18 @@ func AnnotateWorker(conf *GlobalConf, a Annotator, inChan <-chan inProcessIP, for inProcess := range inChan { if fieldName != "" && slices.Contains([]string{"json", "csv"}, conf.InputFileType) { p := inProcess.Out[fieldName].(map[string]interface{}) - p[name] = a.Annotate(inProcess.Ip) + res := a.Annotate(inProcess.Ip) + if isPtrNil(res){ + res = struct{}{} // Don't return null, breaks downstream JSON parsing + } + p[name] = res + } else { - inProcess.Out[name] = a.Annotate(inProcess.Ip) + res := a.Annotate(inProcess.Ip) + if isPtrNil(res){ + res = struct{}{} // Don't return null, breaks downstream JSON parsing + } + inProcess.Out[name] = res } outChan <- inProcess } diff --git a/censys.go b/censys.go index bb98061..1de7c76 100644 --- a/censys.go +++ b/censys.go @@ -83,7 +83,6 @@ var censysAPIHostLookupURL = "https://api.platform.censys.io/v3/global/asset/hos // Annotate performs a Censys host lookup for the given IP address and returns the results. // If an error occurs or a lookup fails, it returns nil func (a *CensysAnnotator) Annotate(ip net.IP) interface{} { - req, err := http.NewRequest("GET", censysAPIHostLookupURL+ip.String(), nil) if err != nil { // If we can't even form a request, we'll fail to enrich anything. Erroring out. From 7ef9657208b390e2acc1b75157573b3138056688 Mon Sep 17 00:00:00 2001 From: phillip-stephens Date: Wed, 6 May 2026 14:36:39 +1200 Subject: [PATCH 2/2] lint --- annotate.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/annotate.go b/annotate.go index 12e4d1d..f7950e3 100644 --- a/annotate.go +++ b/annotate.go @@ -253,7 +253,7 @@ func isPtrNil(i any) bool { } val := reflect.ValueOf(i) switch val.Kind() { - case reflect.Ptr, reflect.Interface, reflect.Slice, reflect.Map: + case reflect.Pointer, reflect.Interface, reflect.Slice, reflect.Map: return val.IsNil() default: return false @@ -272,14 +272,14 @@ func AnnotateWorker(conf *GlobalConf, a Annotator, inChan <-chan inProcessIP, if fieldName != "" && slices.Contains([]string{"json", "csv"}, conf.InputFileType) { p := inProcess.Out[fieldName].(map[string]interface{}) res := a.Annotate(inProcess.Ip) - if isPtrNil(res){ + if isPtrNil(res) { res = struct{}{} // Don't return null, breaks downstream JSON parsing } p[name] = res } else { res := a.Annotate(inProcess.Ip) - if isPtrNil(res){ + if isPtrNil(res) { res = struct{}{} // Don't return null, breaks downstream JSON parsing } inProcess.Out[name] = res