1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

make duplicate headers append instead of get ignored

The code to prevent memory leaks caused by reallocating a wsi->utf8_token
was also causing wsi->parser_state to not be updated, preventing the
handshake from completing.

This patch changes the logic to append to previous allocation which is
correct behaviour actually.

Signed-off-by: Nick Dowell <nick@nickdowell.com>
Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
Nick Dowell 2012-04-05 10:31:48 +08:00 committed by Andy Green
parent c04c193dc3
commit 3059263e3f

View file

@ -190,17 +190,18 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
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;
wsi->utf8_token[wsi->parser_state].token =
malloc(wsi->current_alloc_len);
wsi->utf8_token[wsi->parser_state].token_len = 0;
n = WSI_TOKEN_COUNT;
/* If the header has been seen already, just append */
if (wsi->utf8_token[wsi->parser_state].token)
continue;
wsi->current_alloc_len = LWS_INITIAL_HDR_ALLOC;
wsi->utf8_token[wsi->parser_state].token =
malloc(wsi->current_alloc_len);
wsi->utf8_token[wsi->parser_state].token_len = 0;
}
/* colon delimiter means we just don't know this name */