ws-server: restrict returned Sec-Websocket-Protocol to the chosen name only 28/105328/1 accepted/tizen_3.0.m2_mobile accepted/tizen_3.0.m2_tv accepted/tizen_3.0.m2_wearable accepted/tizen_3.0_common accepted/tizen_3.0_ivi accepted/tizen_3.0_mobile accepted/tizen_3.0_tv accepted/tizen_3.0_wearable accepted/tizen_common accepted/tizen_ivi accepted/tizen_mobile accepted/tizen_tv accepted/tizen_wearable tizen_3.0.m2 tizen_3.0_tv accepted/tizen/3.0.m2/mobile/20170105.024727 accepted/tizen/3.0.m2/tv/20170105.024907 accepted/tizen/3.0.m2/wearable/20170105.025032 accepted/tizen/3.0/common/20161220.101248 accepted/tizen/3.0/ivi/20161220.010528 accepted/tizen/3.0/mobile/20161220.010434 accepted/tizen/3.0/tv/20161220.010450 accepted/tizen/3.0/wearable/20161220.010508 accepted/tizen/common/20161219.152124 accepted/tizen/ivi/20161219.225127 accepted/tizen/mobile/20161219.225030 accepted/tizen/tv/20161219.225048 accepted/tizen/unified/20170309.040104 accepted/tizen/wearable/20161219.225107 submit/tizen/20161219.052346 submit/tizen_3.0.m2/20170104.093753 submit/tizen_3.0/20161219.052217 submit/tizen_3.0/20161219.052244 submit/tizen_unified/20170308.100414 tizen_4.0.m1_release
authorAndy Green <andy@warmcat.com>
Sat, 10 Dec 2016 01:14:37 +0000 (09:14 +0800)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Fri, 16 Dec 2016 08:19:28 +0000 (11:19 +0300)
https://libwebsockets.org/pipermail/libwebsockets/2016-November/002948.html

Updated to fix a problem with no protocol

https://github.com/warmcat/libwebsockets/issues/705

Change-Id: I06e9f9d5849e66291b246316008c6e2c5981a372

lib/server-handshake.c

index 7328e5e..ed257de 100644 (file)
@@ -214,7 +214,12 @@ handshake_0405(struct lws_context *context, struct lws *wsi)
        strcpy(p, (char *)pt->serv_buf);
        p += accept_len;
 
-       if (wsi->protocol->name && wsi->protocol->name[0]) {
+       /* we can only return the protocol header if:
+        *  - one came in, and ... */
+       if (lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL) &&
+           /*  - it is not an empty string */
+           wsi->protocol->name &&
+           wsi->protocol->name[0]) {
                LWS_CPYAPP(p, "\x0d\x0aSec-WebSocket-Protocol: ");
                p += lws_snprintf(p, 128, "%s", wsi->protocol->name);
        }