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

http: proxy server: move C99 VLA to heap

This commit is contained in:
Andy Green 2022-02-07 13:35:23 +00:00
parent 99a8b9c442
commit 8cc4c1713d

View file

@ -1252,8 +1252,9 @@ lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit,
struct lws_client_connect_info i; struct lws_client_connect_info i;
struct lws *cwsi; struct lws *cwsi;
int n, na; int n, na;
unsigned int max_http_header_data = wsi->a.context->max_http_header_data > 256 ? wsi->a.context->max_http_header_data : 256; unsigned int max_http_header_data = wsi->a.context->max_http_header_data > 256 ?
char rpath[max_http_header_data]; wsi->a.context->max_http_header_data : 256;
char *rpath = NULL;
#if defined(LWS_ROLE_WS) #if defined(LWS_ROLE_WS)
if (ws) if (ws)
@ -1320,6 +1321,12 @@ lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit,
if (pcolon) if (pcolon)
i.port = atoi(pcolon + 1); i.port = atoi(pcolon + 1);
rpath = lws_malloc(max_http_header_data, __func__);
if (!rpath)
return -1;
/* rpath needs cleaning after this... ---> */
n = lws_snprintf(rpath, max_http_header_data - 1, "/%s/%s", n = lws_snprintf(rpath, max_http_header_data - 1, "/%s/%s",
pslash + 1, uri_ptr + hit->mountpoint_len) - 1; pslash + 1, uri_ptr + hit->mountpoint_len) - 1;
lws_clean_url(rpath); lws_clean_url(rpath);
@ -1341,7 +1348,7 @@ lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit,
lwsl_info("%s: query string %d longer " lwsl_info("%s: query string %d longer "
"than we can handle\n", __func__, "than we can handle\n", __func__,
na); na);
lws_free(rpath);
return -1; return -1;
} }
@ -1371,10 +1378,9 @@ lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit,
#endif #endif
{ {
n = lws_hdr_total_length(wsi, WSI_TOKEN_HOST); n = lws_hdr_total_length(wsi, WSI_TOKEN_HOST);
if (n > 0) { if (n > 0)
i.host = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST); i.host = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST);
} }
}
#if 0 #if 0
if (i.address[0] != '+' || if (i.address[0] != '+' ||
@ -1467,9 +1473,10 @@ lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit,
"The server is temporarily unable to service " "The server is temporarily unable to service "
"your request due to maintenance downtime or " "your request due to maintenance downtime or "
"capacity problems. Please try again later."); "capacity problems. Please try again later.");
lws_free(rpath);
return 1; return 1;
} }
lws_free(rpath);
lwsl_info("%s: setting proxy clientside on %s (parent %s)\n", lwsl_info("%s: setting proxy clientside on %s (parent %s)\n",
__func__, lws_wsi_tag(cwsi), lws_wsi_tag(lws_get_parent(cwsi))); __func__, lws_wsi_tag(cwsi), lws_wsi_tag(lws_get_parent(cwsi)));