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

lws_get_urlarg_by_name: drop candidates that wont fit in buf rather than bail

https://github.com/warmcat/libwebsockets/issues/3227
This commit is contained in:
Andy Green 2024-09-28 06:01:36 +01:00
parent c60bff0991
commit 9dbbd45170
3 changed files with 5 additions and 4 deletions

View file

@ -436,7 +436,7 @@ lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
/**
* lws_hdr_copy_fragment() - copy a single fragment of the given header to a buffer
* The buffer length len must include space for an additional
* terminating '\0', or it will fail returning -1.
* terminating '\0', or it will fail returning -2.
* If the requested fragment index is not present, it fails
* returning -1.
*

View file

@ -746,10 +746,11 @@ lws_get_urlarg_by_name_safe(struct lws *wsi, const char *name, char *buf, int le
fraglen = lws_hdr_copy_fragment(wsi, buf, len,
WSI_TOKEN_HTTP_URI_ARGS, n);
if (fraglen < 0)
if (fraglen == -1) /* no fragment or basic problem */
break;
if (fraglen + 1 < len &&
if (fraglen > 0 && /* fragment could fit */
fraglen + 1 < len &&
fraglen >= sl &&
!strncmp(buf, name, (size_t)sl)) {
/*

View file

@ -520,7 +520,7 @@ int lws_hdr_copy_fragment(struct lws *wsi, char *dst, int len,
}
if (wsi->http.ah->frags[f].len >= len)
return -1;
return -2;
memcpy(dst, wsi->http.ah->data + wsi->http.ah->frags[f].offset,
wsi->http.ah->frags[f].len);