mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 18:25:25 +00:00
fix memory leak in dns templates (#3676)
* fix memory leak * update test to cover the string slice case
This commit is contained in:
parent
e995b0ce48
commit
06ab56abea
@ -96,7 +96,10 @@ func (request *Request) responseToDSLMap(req, resp *dns.Msg, host, matched strin
|
||||
"type": request.Type().String(),
|
||||
"trace": traceToString(traceData, false),
|
||||
}
|
||||
return generators.MergeMaps(ret, recordsKeyValue(resp.Answer))
|
||||
if len(resp.Answer) > 0 {
|
||||
ret = generators.MergeMaps(ret, recordsKeyValue(resp.Answer))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// MakeResultEvent creates a result event from internal wrapped event
|
||||
@ -156,12 +159,14 @@ func recordsKeyValue(resourceRecords []dns.RR) output.InternalEvent {
|
||||
key := strings.ToLower(dns.TypeToString[resourceRecord.Header().Rrtype])
|
||||
value := strings.ReplaceAll(resourceRecord.String(), resourceRecord.Header().String(), "")
|
||||
|
||||
if preVal, ok := oe[key]; ok {
|
||||
switch v := oe[key].(type) {
|
||||
// if the key is already present, we need to convert the value to a slice
|
||||
// if the key has slice, then append the value to the slice
|
||||
if previous, ok := oe[key]; ok {
|
||||
switch v := previous.(type) {
|
||||
case string:
|
||||
oe[key] = []string{value, preVal.(string)}
|
||||
oe[key] = []string{v, value}
|
||||
case []string:
|
||||
oe[key] = append(v, preVal.([]string)...)
|
||||
oe[key] = append(v, value)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@ -43,12 +43,12 @@ func TestResponseToDSLMap(t *testing.T) {
|
||||
|
||||
resp := new(dns.Msg)
|
||||
resp.Rcode = dns.RcodeSuccess
|
||||
resp.Answer = append(resp.Answer, &dns.A{A: net.ParseIP("1.1.1.1"), Hdr: dns.RR_Header{Name: "one.one.one.one.", Rrtype: dns.TypeA}}, &dns.A{A: net.ParseIP("2.2.2.2"), Hdr: dns.RR_Header{Name: "one.one.one.one.", Rrtype: dns.TypeA}})
|
||||
resp.Answer = append(resp.Answer, &dns.A{A: net.ParseIP("1.1.1.1"), Hdr: dns.RR_Header{Name: "one.one.one.one.", Rrtype: dns.TypeA}}, &dns.A{A: net.ParseIP("2.2.2.2"), Hdr: dns.RR_Header{Name: "one.one.one.one.", Rrtype: dns.TypeA}}, &dns.A{A: net.ParseIP("3.3.3.3"), Hdr: dns.RR_Header{Name: "one.one.one.one.", Rrtype: dns.TypeA}})
|
||||
|
||||
event := request.responseToDSLMap(req, resp, "one.one.one.one", "one.one.one.one", nil)
|
||||
require.Len(t, event, 15, "could not get correct number of items in dsl map")
|
||||
require.Equal(t, dns.RcodeSuccess, event["rcode"], "could not get correct rcode")
|
||||
require.ElementsMatch(t, []string{net.ParseIP("1.1.1.1").String(), net.ParseIP("2.2.2.2").String()}, event["a"], "could not get correct a record")
|
||||
require.ElementsMatch(t, []string{net.ParseIP("1.1.1.1").String(), net.ParseIP("2.2.2.2").String(), net.ParseIP("3.3.3.3").String()}, event["a"], "could not get correct a record")
|
||||
}
|
||||
|
||||
func TestDNSOperatorMatch(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user