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

Denis Osvald denis.osvald at sartura.hr
Tue Jan 5 10:46:39 CET 2016

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


>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) {

More information about the Libwebsockets mailing list