mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
map wsorigin on to origin at an early point and stop dupe header mem leaks
Carlo wrote ''I'm interested to use the libwebsockets server (C based) with a Java websocket client. I was able to implement a Java websocket client based on JWebSocket library that works fine with the libwebsockets server, but I was obliged to patch the libwebsockets server in order to reach my goal. In particular I patched the handshake_00() function because JWebSocket library uses hixie 76 version. The problem was that the JWebSocket library sends only WSI_TOKEN_SWORIGIN token instead WSI_TOKEN_ORIGIN token. For this reason the handshake_00 failed because the token length of WSI_TOKEN_ORIGIN was 0. I have written a patch in order to control if at least one of the two tokens (WSI_TOKEN_SWORIGIN and WSI_TOKEN_ORIGIN) is defined. I have attached into the e-mail the patch. Probably it can be written better, but in any case I think that this problem should be fixed for client/server compatibility.'' I found a simpler approach which is convert WSORIGIN processing to go into ORIGIN token at the earliest point, then everything else can stay the same. I also noticed we would leak on duplicated headers and fixed that. Reported-by: Carlo PARATA <carlo.parata@st.com> Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
parent
5519d9f054
commit
fd96330920
1 changed files with 12 additions and 0 deletions
|
@ -182,6 +182,18 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
|
|||
if (strcasecmp(lws_tokens[n].token, wsi->name_buffer))
|
||||
continue;
|
||||
debug("known hdr '%s'\n", wsi->name_buffer);
|
||||
|
||||
/*
|
||||
* WSORIGIN is protocol equiv to ORIGIN,
|
||||
* JWebSocket likes to send it, map to ORIGIN
|
||||
*/
|
||||
if (n == WSI_TOKEN_SWORIGIN)
|
||||
n = WSI_TOKEN_ORIGIN;
|
||||
|
||||
/* check for dupe header -> mem leak... skip dupes */
|
||||
if (wsi->utf8_token[WSI_TOKEN_GET_URI + n].token)
|
||||
continue;
|
||||
|
||||
wsi->parser_state = WSI_TOKEN_GET_URI + n;
|
||||
wsi->current_alloc_len = LWS_INITIAL_HDR_ALLOC;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue