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

http: hdr: sync lws_hdr_total_length with lws_hdr_copy

This commit is contained in:
Andy Green 2021-08-27 05:47:31 +01:00
parent 06e881aad6
commit 572e7e03e5

View file

@ -490,8 +490,8 @@ int lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h)
len += wsi->http.ah->frags[n].len;
n = wsi->http.ah->frags[n].nfrag;
if (n && h != WSI_TOKEN_HTTP_COOKIE)
++len;
if (n)
len++;
} while (n);
@ -532,9 +532,7 @@ int lws_hdr_copy_fragment(struct lws *wsi, char *dst, int len,
int lws_hdr_copy(struct lws *wsi, char *dst, int len,
enum lws_token_indexes h)
{
int toklen = lws_hdr_total_length(wsi, h);
int n;
int comma;
int toklen = lws_hdr_total_length(wsi, h), n, comma;
*dst = '\0';
if (!toklen)
@ -548,7 +546,8 @@ int lws_hdr_copy(struct lws *wsi, char *dst, int len,
n = wsi->http.ah->frag_index[h];
if (h == WSI_TOKEN_HTTP_URI_ARGS)
lwsl_err("%s: WSI_TOKEN_HTTP_URI_ARGS start frag %d\n", __func__, n);
lwsl_err("%s: WSI_TOKEN_HTTP_URI_ARGS start frag %d\n",
__func__, n);
if (!n)
@ -557,7 +556,10 @@ int lws_hdr_copy(struct lws *wsi, char *dst, int len,
comma = (wsi->http.ah->frags[n].nfrag) ? 1 : 0;
if (h == WSI_TOKEN_HTTP_URI_ARGS)
lwsl_notice("%s: WSI_TOKEN_HTTP_URI_ARGS '%.*s'\n", __func__, (int)wsi->http.ah->frags[n].len, &wsi->http.ah->data[wsi->http.ah->frags[n].offset]);
lwsl_notice("%s: WSI_TOKEN_HTTP_URI_ARGS '%.*s'\n",
__func__, (int)wsi->http.ah->frags[n].len,
&wsi->http.ah->data[
wsi->http.ah->frags[n].offset]);
if (wsi->http.ah->frags[n].len + comma >= len) {
lwsl_notice("blowout len\n");
@ -569,14 +571,22 @@ 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;
/*
* Note if you change this logic, take care about updating len
* and make sure lws_hdr_total_length() gives the same resulting
* length
*/
if (comma) {
if (h == WSI_TOKEN_HTTP_COOKIE || h == WSI_TOKEN_HTTP_SET_COOKIE)
if (h == WSI_TOKEN_HTTP_COOKIE ||
h == WSI_TOKEN_HTTP_SET_COOKIE)
*dst++ = ';';
else
if (h == WSI_TOKEN_HTTP_URI_ARGS)
*dst++ = '&';
else
*dst++ = ',';
len--;
}
} while (n);