Skip to content

Commit

Permalink
BUG/MINOR Detect partial read from socket
Browse files Browse the repository at this point in the history
It's possible if an external process causes a reload/restart of HAProxy
that the data from the socket will be truncated. If it is not trucated
on a new line then other functions processing the results will have
malformed data and likely cause a panic.

Resolves haproxytech#44
  • Loading branch information
jaredcurtis committed Sep 21, 2020
1 parent 0f8b5d6 commit 42d3b48
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion runtime/runtime_single_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package runtime

import (
"errors"
"fmt"
"net"
"strings"
Expand Down Expand Up @@ -101,7 +102,17 @@ func (s *SingleRuntime) readFromSocket(command string) (string, error) {
if err != nil {
return "", err
}
result := strings.TrimSuffix(data.String(), "\n> ")

// Check that last 2 bytes are a LF, otherwise we received an incomplete response
results := data.String()
if len(results) > 2 {
if results[len(results)-2:] != "\n\n" {
err := errors.New("Incomplete read from socket")
return results, err
}
}

result := strings.TrimSuffix(results, "\n> ")
result = strings.TrimSuffix(result, "\n")
return result, nil
}
Expand Down

0 comments on commit 42d3b48

Please sign in to comment.