bitly/nsq — pull request #120 by michaelhood (2013-01-05 11:40:34+00:00)
Title: nsqd crashes if you send a reader sends an "empty" command

NSQ will crash with a panic if a connected reader sends command(s) to nsqd that, after slicing on `\n`, leaves a command to be processed which consists of *only* `\n`.

An improperly behaving reader doing variations of the following will lead to a crash in nsqd:

c.send("CLS\n\n")
c.send("\n\n")

Bug appears to have been introduced in [e7e9686](e7e9686#L3R49), in `nsqd/protocol_v2.go`.

Trace excerpt follows.

```
panic: runtime error: index out of range

goroutine 41 [running]:
main.(*ProtocolV2).IOLoop(0xf8400898f0, 0xf8401d31e0, 0xf840095670, 0xf84007c750, 0xf8400898f0, ...)
[…]/nsq/nsqd/protocol_v2.go:50 +0x27c
main.(*TcpProtocol).Handle(0xf840209000, 0xf8401d31e0, 0xf840095670, 0x0)
[…]/nsq/nsqd/tcp.go:33 +0x504
created by _[…]/nsq/util.TcpServer
[…]/nsq/util/tcp_server.go:31 +0x484
```