simonz05/godis — Issue #1: calling New with a bad netaddr
Author: stratos00
Created: 2011-11-18 19:51:54+00:00
State: open

Hello,

First off, thanks for contributing the library. It appears to work pretty well.

If you call New with bad netaddr (i.e. 127.0.0.1 instead of 127.0.0.1:6379) then you will get a panic.

Here is the snippet:

na := strings.SplitN(netaddr, ":", 2)
return &Client{Addr: na[1], Db: db, Password: password, net: na[0], pool: newPool()}

If there is not a colon in the addr passed then an index error occurs.

I'm not sure what the best mechanism is to address. You could check the length like this:

if len(na) != 2 {
return nil
}

Or you could check before calling split and do the same with strings.IndexRune(netaddr, ":").

Or you could make sure that it a valid net addr by doing a net.ResolveTCPAddr("tcp4", netaddr) and catch it on the error.

Was going to fork this and send a pull request just didn't wanted to do so without getting a stylistic blessing.

Thanks again!

Shelby