From 4bb64be27e560ebd889cd5dea0c480c47c6adf59 Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Thu, 14 Sep 2017 22:35:45 +0500 Subject: [PATCH] Fix panic when reading too big response in debug mode --- http_client.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/http_client.go b/http_client.go index ef91696..6bc2c11 100644 --- a/http_client.go +++ b/http_client.go @@ -297,14 +297,22 @@ func (c *HTTPClient) Send(data []byte) (response []byte, err error) { } if err != nil && readBytes == 0 { - Debug("[HTTPClient] Response read timeout error", err, c.conn, readBytes, string(c.respBuf[:readBytes])) + maxRead := 100 + if readBytes < maxRead { + maxRead = readBytes + } + Debug("[HTTPClient] Response read timeout error", err, c.conn, readBytes, string(c.respBuf[:maxRead])) response = errorPayload(HTTP_TIMEOUT) c.Disconnect() return } if readBytes < 4 || string(c.respBuf[:4]) != "HTTP" { - Debug("[HTTPClient] Response read unknown error", err, c.conn, readBytes, string(c.respBuf[:readBytes])) + maxRead := 100 + if readBytes < maxRead { + maxRead = readBytes + } + Debug("[HTTPClient] Response read unknown error", err, c.conn, readBytes, string(c.respBuf[:maxRead])) response = errorPayload(HTTP_UNKNOWN_ERROR) c.Disconnect() return