Skip to content

Commit

Permalink
Fix 'index out of range' bug in Packetbeat DNS protocol plugin
Browse files Browse the repository at this point in the history
When converting resource records into MapStrs the code can run into an index out of range exception when processing OPT psuedo resource records. The code reduces the size of a slice by creating a new, smaller slice and copies the existing data to the smaller slice. But the code did not account for the fact that the length of the slice was smaller when indexing.

Fixes elastic#2872
  • Loading branch information
andrewkroh committed Oct 28, 2016
1 parent d1d8e31 commit cbde106
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ https://github.com/elastic/beats/compare/v5.0.0...master[Check the HEAD diff]

*Packetbeat*

- Fix 'index out of bounds' bug in Packetbeat DNS protocol plugin. {issue}2872[2872]

*Topbeat*

*Filebeat*
Expand Down
13 changes: 5 additions & 8 deletions packetbeat/protos/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,26 +529,23 @@ func optToMapStr(rrOPT *mkdns.OPT) common.MapStr {
return optMapStr
}

// rrsToMapStr converts an array of RR's to an array of MapStr's.
// rrsToMapStr converts an slice of RR's to an slice of MapStr's.
func rrsToMapStrs(records []mkdns.RR) []common.MapStr {
mapStrArray := make([]common.MapStr, len(records))
for i, rr := range records {
mapStrSlice := make([]common.MapStr, 0, len(records))
for _, rr := range records {
rrHeader := rr.Header()

mapStr := rrToMapStr(rr)
if len(mapStr) == 0 { // OPT pseudo-RR returns an empty MapStr
resizeStrArray := make([]common.MapStr, len(mapStrArray)-1)
copy(resizeStrArray, mapStrArray)
mapStrArray = resizeStrArray
continue
}
mapStr["name"] = rrHeader.Name
mapStr["type"] = dnsTypeToString(rrHeader.Rrtype)
mapStr["class"] = dnsClassToString(rrHeader.Class)
mapStr["ttl"] = strconv.FormatInt(int64(rrHeader.Ttl), 10)
mapStrArray[i] = mapStr
mapStrSlice = append(mapStrSlice, mapStr)
}
return mapStrArray
return mapStrSlice
}

// Convert all RDATA fields of a RR to a single string
Expand Down

0 comments on commit cbde106

Please sign in to comment.