From 11dfeb5a41495ceae4fa60a453ff9f82e50bb7d2 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Mon, 13 Jan 2025 09:29:37 +0100 Subject: [PATCH 1/3] http/server: increase BUFSIZE_MAX to 1 MB --- src/http/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http/server.c b/src/http/server.c index 241c31667..038e45d82 100644 --- a/src/http/server.c +++ b/src/http/server.c @@ -22,7 +22,7 @@ enum { TIMEOUT_IDLE = 600000, TIMEOUT_INIT = 10000, - BUFSIZE_MAX = 524288, + BUFSIZE_MAX = 1024 * 1024 * 1, /* 1 MB */ }; struct http_sock { From f7ba47d1325d272e63dadaa3879c73b67c548202 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Mon, 13 Jan 2025 09:30:01 +0100 Subject: [PATCH 2/3] http/server: add http_set_max_body_size --- include/re_http.h | 1 + src/http/server.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/re_http.h b/include/re_http.h index 1ac3eafba..0a97f3ce7 100644 --- a/include/re_http.h +++ b/include/re_http.h @@ -202,6 +202,7 @@ int https_listen(struct http_sock **sockp, const struct sa *laddr, const char *cert, http_req_h *reqh, void *arg); int https_set_verify_msgh(struct http_sock *sock, https_verify_msg_h *verifyh); +void http_set_max_body_size(struct http_sock *sock, size_t limit); struct tcp_sock *http_sock_tcp(struct http_sock *sock); struct tls *http_sock_tls(const struct http_sock *conn); const struct sa *http_conn_peer(const struct http_conn *conn); diff --git a/src/http/server.c b/src/http/server.c index 038e45d82..1436aa05f 100644 --- a/src/http/server.c +++ b/src/http/server.c @@ -31,6 +31,7 @@ struct http_sock { struct tls *tls; http_req_h *reqh; https_verify_msg_h *verifyh; + size_t max_body_size; void *arg; }; @@ -212,7 +213,8 @@ static void recv_handler(struct mbuf *mb, void *arg) const size_t len = mbuf_get_left(mb), pos = conn->mb->pos; - if ((mbuf_get_left(conn->mb) + len) > BUFSIZE_MAX) { + if ((mbuf_get_left(conn->mb) + len) > + conn->sock->max_body_size) { err = EOVERFLOW; goto out; } @@ -376,6 +378,7 @@ int http_listen_fd(struct http_sock **sockp, re_sock_t fd, http_req_h *reqh, sock->reqh = reqh; sock->arg = arg; + sock->max_body_size = BUFSIZE_MAX; out: if (err) @@ -416,6 +419,7 @@ int http_listen(struct http_sock **sockp, const struct sa *laddr, sock->reqh = reqh; sock->arg = arg; + sock->max_body_size = BUFSIZE_MAX; out: if (err) @@ -496,6 +500,21 @@ int https_set_verify_msgh(struct http_sock *sock, } +/** + * Set Request buffer size limit + * + * @param sock HTTP socket + * @param limit New limit in bytes + */ +void http_set_max_body_size(struct http_sock *sock, size_t limit) +{ + if (!sock) + return; + + sock->max_body_size = limit; +} + + /** * Get the TCP socket of an HTTP socket * From bcb8a3c38bc2cc5287171e9ca68bce88f46f9e62 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Mon, 13 Jan 2025 09:36:02 +0100 Subject: [PATCH 3/3] test/http: add http_set_max_body_size --- test/http.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/http.c b/test/http.c index 8c5788543..9aa7c9fc7 100644 --- a/test/http.c +++ b/test/http.c @@ -499,6 +499,8 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn, if (err) goto out; + http_set_max_body_size(sock, 1024 * 1024 / 2); + err = tcp_sock_local_get(http_sock_tcp(sock), &srv); if (err) goto out;