Skip to content

Commit

Permalink
ignore leading spaces when checking for a suitable subprotocol
Browse files Browse the repository at this point in the history
My Browsers send as Subprotocols e.g. chat, superchat, mySubprotocol (with spaces after the ,). Libwebsockets now checked if ' mySubprotocol' was equal to 'mySubprotocol' which failed. With this fix the leading space is ignored and uses 'mySubprotocol' for comparision.
  • Loading branch information
tobiasgraf authored and lws-team committed Jan 16, 2017
1 parent b837f93 commit 3f55e5e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
struct _lws_header_related hdr;
struct allocated_headers *ah;
int protocol_len, n = 0, hit;
int protocol_len, n = 0, hit, non_space_char_found = 0;
char protocol_list[128];
char protocol_name[64];
char *p;
Expand Down Expand Up @@ -1341,8 +1341,17 @@ lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)

while (*p && !hit) {
n = 0;
while (n < sizeof(protocol_name) - 1 && *p && *p !=',')
non_space_char_found = 0;
while (n < sizeof(protocol_name) - 1 && *p &&
*p != ',') {
// ignore leading spaces
if (!non_space_char_found && *p == ' ') {
n++;
continue;
}
non_space_char_found = 1;
protocol_name[n++] = *p++;
}
protocol_name[n] = '\0';
if (*p)
p++;
Expand Down

0 comments on commit 3f55e5e

Please sign in to comment.