handle unsupported protocol correctly
authorNick Dowell <nick@nickdowell.com>
Tue, 3 Apr 2012 16:22:19 +0000 (17:22 +0100)
committerAndy Green <andy.green@linaro.org>
Wed, 4 Apr 2012 00:27:35 +0000 (08:27 +0800)
Hi Andy,

First off, thanks for libwebsockets :-)

I've encountered a crash when a client connects to a libwebsockets server
but speicifies an unsupported protocol (Sec-WebSocket-Protocol).
handshake.c should probably be checking that wsi->protocol->name is not
null before doing a strcmp with it...
Attached is a patch for your consideration.

Cheers!
Nick

Signed-off-by: Nick Dowell <nick@nickdowell.com>
lib/handshake.c

index dafccef..dca2e14 100644 (file)
@@ -619,7 +619,7 @@ libwebsocket_read(struct libwebsocket_context *context, struct libwebsocket *wsi
                                if (wsi->protocol->name == NULL)
                                        break;
                        } else
-                               if (strcmp(
+                               if (wsi->protocol->name && strcmp(
                                     wsi->utf8_token[WSI_TOKEN_PROTOCOL].token,
                                                      wsi->protocol->name) == 0)
                                        break;