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

lws_hdr_total_length: match lws_hdr_copy actual length also for COOKIE

This commit is contained in:
Wei Zhang 2018-11-15 15:35:22 +08:00 committed by Andy Green
parent 0a0b88174d
commit 8750582fc6

View file

@ -459,6 +459,10 @@ LWS_VISIBLE int lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h)
do {
len += wsi->http.ah->frags[n].len;
n = wsi->http.ah->frags[n].nfrag;
if (n && h != WSI_TOKEN_HTTP_COOKIE)
++len;
} while (n);
return len;
@ -500,6 +504,7 @@ LWS_VISIBLE int lws_hdr_copy(struct lws *wsi, char *dst, int len,
{
int toklen = lws_hdr_total_length(wsi, h);
int n;
int comma;
*dst = '\0';
if (!toklen)
@ -516,7 +521,9 @@ LWS_VISIBLE int lws_hdr_copy(struct lws *wsi, char *dst, int len,
return 0;
do {
if (wsi->http.ah->frags[n].len + 1 >= len)
comma = (wsi->http.ah->frags[n].nfrag && h != WSI_TOKEN_HTTP_COOKIE) ? 1 : 0;
if (wsi->http.ah->frags[n].len + comma >= len)
return -1;
strncpy(dst, &wsi->http.ah->data[wsi->http.ah->frags[n].offset],
wsi->http.ah->frags[n].len);
@ -524,9 +531,9 @@ LWS_VISIBLE int lws_hdr_copy(struct lws *wsi, char *dst, int len,
len -= wsi->http.ah->frags[n].len;
n = wsi->http.ah->frags[n].nfrag;
if (n)
if (h != WSI_TOKEN_HTTP_COOKIE)
*dst++ = ',';
if (comma)
*dst++ = ',';
} while (n);
*dst = '\0';