[Libwebsockets] [PATCH] properly skip protocols with NULL name

Denis Osvald denis.osvald at sartura.hr
Wed Jan 6 18:00:13 CET 2016


Hi,

The patch in my original message has mangled whitespace.

Here's another attempt at posting it to the list inline.
If it still doesn't work I'l put an attachment.

Regards,
Denis


>From 22eb9de7d7f222da08ad3f2f28d1adacdcff5216 Mon Sep 17 00:00:00 2001
From: Denis Osvald <denis.osvald at sartura.hr>
Date: Mon, 21 Dec 2015 16:39:59 +0100
Subject: [PATCH] properly skip protocols with NULL name

Signed-off-by: Denis Osvald <denis.osvald at sartura.hr>
---
 lib/server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/server.c b/lib/server.c
index c60405e..d63fe08 100644
--- a/lib/server.c
+++ b/lib/server.c
@@ -458,7 +458,7 @@ upgrade_ws:
 
 			n = 0;
 			while (wsi->protocol && context->protocols[n].callback) {
-				if (!wsi->protocol->name) {
+				if (!context->protocols[n].name) {
 					n++;
 					continue;
 				}
-- 
2.6.4



On 01/05/2016 10:46 AM, Denis Osvald wrote:
> Hi all,
> 
> I have questions and a change suggestion for libwebsockets.
> 
> It should be possible to make protocol[0] name = NULL so that it never
> matches an actual subprotocol, and so protocols[0] only handles
> no-protocol-specified clients and misc. handshake phases. Currently if
> we set NULL as name (i.e. something we can be sure no client can send as
> subprotocol name) subprotocol matching doesn't work.
> 
> I believe this is due to a bug in LWS, specifically, when checking the
> client's protocols in lib/server.c:477, the check for NULL should look at
> context->protocols[n]->name not wsi->protocols->name
> 
> I have locally tested the fix proposed in patch below
> 
> Currently I am working around this by specifying the protocols[0] name
> as a comma, since commas will be split out of client-given subprotocol
> names and so comma will never match a client's subprotocol name.
> 
> But I believe it could be more clear that we don't want to match a
> subprotocol name by using NULL. So please consider the patch
> 
> Regards,
> Denis
> 
> 
> From a24e613d3e0a89bf6ab5dad6d188f6ed5ae74043 Mon Sep 17 00:00:00 2001
> From: Denis Osvald <denis.osvald at sartura.hr>
> Date: Mon, 21 Dec 2015 16:39:59 +0100
> Subject: [PATCH] properly skip protocols with NULL name
> 
> Signed-off-by: Denis Osvald <denis.osvald at sartura.hr>
> ---
>  lib/server.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/server.c b/lib/server.c
> index 7e728f3..791918f 100644
> --- a/lib/server.c
> +++ b/lib/server.c
> @@ -474,7 +474,7 @@ upgrade_ws:
>   			n = 0;
>  			while (wsi->protocol && context->protocols[n].callback) {
> -				if (!wsi->protocol->name) {
> +				if (!context->protocols[n].name) {
>  					n++;
>  					continue;
>  				}
> 



More information about the Libwebsockets mailing list