From 8a4ccc8e9975c4133981a849144d81e63cee88b1 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Mon, 15 Jan 2018 10:53:08 -0700 Subject: [PATCH] Fix server crash when receiving zero arg commands. fix #246 --- controller/server/reader.go | 40 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/controller/server/reader.go b/controller/server/reader.go index fe0d6fb1..a5c6585c 100644 --- a/controller/server/reader.go +++ b/controller/server/reader.go @@ -223,27 +223,29 @@ moreData: if !complete { break } - if kind != kindHTTP { - msg.Command = strings.ToLower(string(args[0])) - for i := 0; i < len(args); i++ { - args[i] = append([]byte{}, args[i]...) - msg.Values = append(msg.Values, resp.BytesValue(args[i])) + if len(args) > 0 { + if kind != kindHTTP { + msg.Command = strings.ToLower(string(args[0])) + for i := 0; i < len(args); i++ { + args[i] = append([]byte{}, args[i]...) + msg.Values = append(msg.Values, resp.BytesValue(args[i])) + } + switch kind { + case redcon.Redis: + msg.ConnType = RESP + msg.OutputType = RESP + case redcon.Tile38: + msg.ConnType = Native + msg.OutputType = JSON + case redcon.Telnet: + msg.ConnType = RESP + msg.OutputType = RESP + } + } else if len(msg.Values) == 0 { + return nil, errInvalidHTTP } - switch kind { - case redcon.Redis: - msg.ConnType = RESP - msg.OutputType = RESP - case redcon.Tile38: - msg.ConnType = Native - msg.OutputType = JSON - case redcon.Telnet: - msg.ConnType = RESP - msg.OutputType = RESP - } - } else if len(msg.Values) == 0 { - return nil, errInvalidHTTP + msgs = append(msgs, msg) } - msgs = append(msgs, msg) data = leftover } if len(data) > 0 {