fix(inputs.phpfpm): Check address length to avoid crash (#13495)

This commit is contained in:
Joshua Powers 2023-06-26 11:06:29 -06:00 committed by GitHub
parent 45f994268c
commit 6f6e49d615
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -116,6 +116,9 @@ func (p *phpfpm) gatherServer(addr string, acc telegraf.Accumulator) error {
return fmt.Errorf("unable parse server address %q: %w", addr, err)
}
socketAddr := strings.Split(u.Host, ":")
if len(socketAddr) < 2 {
return fmt.Errorf("url does not follow required 'address:port' format: %s", u.Host)
}
fcgiIP := socketAddr[0]
fcgiPort, _ := strconv.Atoi(socketAddr[1])
fcgi, err = newFcgiClient(fcgiIP, fcgiPort)