properly skip protocols with NULL name
authorDenis Osvald <denis.osvald@sartura.hr>
Mon, 21 Dec 2015 15:39:59 +0000 (16:39 +0100)
committerAndy Green <andy.green@linaro.org>
Wed, 6 Jan 2016 22:57:59 +0000 (06:57 +0800)
Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
lib/server.c

index c60405e..c24f9b1 100644 (file)
@@ -457,12 +457,9 @@ upgrade_ws:
                        lwsl_info("checking %s\n", protocol_name);
 
                        n = 0;
-                       while (wsi->protocol && context->protocols[n].callback) {
-                               if (!wsi->protocol->name) {
-                                       n++;
-                                       continue;
-                               }
-                               if (!strcmp(context->protocols[n].name,
+                       while (context->protocols[n].callback) {
+                               if (context->protocols[n].name &&
+                                   !strcmp(context->protocols[n].name,
                                            protocol_name)) {
                                        lwsl_info("prot match %d\n", n);
                                        wsi->protocol = &context->protocols[n];
@@ -477,19 +474,18 @@ upgrade_ws:
                /* we didn't find a protocol he wanted? */
 
                if (!hit) {
-                       if (!lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL)) {
-                               /*
-                                * some clients only have one protocol and
-                                * do not sent the protocol list header...
-                                * allow it and match to protocol 0
-                                */
-                               lwsl_info("defaulting to prot 0 handler\n");
-                               wsi->protocol = &context->protocols[0];
-                       } else {
-                               lwsl_err("No protocol from list \"%s\" supported\n",
+                       if (lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL)) {
+                               lwsl_err("No protocol from \"%s\" supported\n",
                                         protocol_list);
                                goto bail_nuke_ah;
                        }
+                       /*
+                        * some clients only have one protocol and
+                        * do not sent the protocol list header...
+                        * allow it and match to protocol 0
+                        */
+                       lwsl_info("defaulting to prot 0 handler\n");
+                       wsi->protocol = &context->protocols[0];
                }
 
                /* allocate wsi->user storage */
@@ -509,7 +505,6 @@ upgrade_ws:
                        goto bail_nuke_ah;
                }
 
-
                /*
                 * Perform the handshake according to the protocol version the
                 * client announced