Skip to content

Commit

Permalink
Add Regex Length Checks To Avoid Panics (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
kolanos authored Nov 1, 2021
1 parent 5d2c26b commit d7c20a3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lambda/logserver/logserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func formatReport(metrics map[string]interface{}) string {
return ret
}

var reportStringRegExp, _ = regexp.Compile("RequestId: ([a-zA-Z0-9-]+)(.*)")
var reportStringRegExp, _ = regexp.Compile("RequestId: ([a-fA-F0-9-]+)(.*)")

func (ls *LogServer) handler(res http.ResponseWriter, req *http.Request) {
defer util.Close(req.Body)
Expand All @@ -126,7 +126,10 @@ func (ls *LogServer) handler(res http.ResponseWriter, req *http.Request) {
ls.lastRequestId = event.Record.(map[string]interface{})["requestId"].(string)
case string:
recordString := event.Record.(string)
ls.lastRequestId = reportStringRegExp.FindStringSubmatch(recordString)[1]
results := reportStringRegExp.FindStringSubmatch(recordString)
if len(results) > 1 {
ls.lastRequestId = results[1]
}
}
ls.lastRequestIdLock.Unlock()
case "platform.report":
Expand All @@ -141,8 +144,14 @@ func (ls *LogServer) handler(res http.ResponseWriter, req *http.Request) {
case string:
recordString := event.Record.(string)
results := reportStringRegExp.FindStringSubmatch(recordString)
requestId = results[1]
metricString = results[2]
if len(results) > 1 {
requestId = results[1]
if len(results) > 2 {
metricString = results[2]
}
} else {
util.Debugf("Unknown platform log: %s", recordString)
}
}

reportStr := fmt.Sprintf(
Expand Down

0 comments on commit d7c20a3

Please sign in to comment.