Fix server crash when receiving zero arg commands.

fix #246
This commit is contained in:
Josh Baker 2018-01-15 10:53:08 -07:00
parent 1f70cb4e75
commit 8a4ccc8e99
1 changed files with 21 additions and 19 deletions

View File

@ -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 {