1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +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 15a078c2cc
commit a85b70bfe6

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; len += wsi->http.ah->frags[n].len;
n = wsi->http.ah->frags[n].nfrag; n = wsi->http.ah->frags[n].nfrag;
if (n && h != WSI_TOKEN_HTTP_COOKIE) if (n)
++len; len++;
} while (n); } 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, int lws_hdr_copy(struct lws *wsi, char *dst, int len,
enum lws_token_indexes h) enum lws_token_indexes h)
{ {
int toklen = lws_hdr_total_length(wsi, h); int toklen = lws_hdr_total_length(wsi, h), n, comma;
int n;
int comma;
*dst = '\0'; *dst = '\0';
if (!toklen) if (!toklen)
@ -548,7 +546,8 @@ int lws_hdr_copy(struct lws *wsi, char *dst, int len,
n = wsi->http.ah->frag_index[h]; n = wsi->http.ah->frag_index[h];
if (h == WSI_TOKEN_HTTP_URI_ARGS) 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) 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; comma = (wsi->http.ah->frags[n].nfrag) ? 1 : 0;
if (h == WSI_TOKEN_HTTP_URI_ARGS) 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) { if (wsi->http.ah->frags[n].len + comma >= len) {
lwsl_notice("blowout len\n"); 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; len -= wsi->http.ah->frags[n].len;
n = wsi->http.ah->frags[n].nfrag; 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 (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++ = ';'; *dst++ = ';';
else else
if (h == WSI_TOKEN_HTTP_URI_ARGS) if (h == WSI_TOKEN_HTTP_URI_ARGS)
*dst++ = '&'; *dst++ = '&';
else else
*dst++ = ','; *dst++ = ',';
len--;
} }
} while (n); } while (n);