From 7d679f9ab6f159483cd24b633eda0f33d2330418 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 14 Mar 2025 17:30:09 +0100 Subject: [PATCH] http: remove a HTTP method size restriction By allocating the method string as part of the struct, the previous fixed size limit (23 bytes) can be avoided. It would previously make "curl -X [long string]" work against http://localhost but fail against https://curl.se with no clear error message. Closes #16729 --- lib/http.c | 12 ++++-------- lib/http.h | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/http.c b/lib/http.c index 5256ee7ead..03d1959e29 100644 --- a/lib/http.c +++ b/lib/http.c @@ -4238,11 +4238,9 @@ CURLcode Curl_http_req_make(struct httpreq **preq, struct httpreq *req; CURLcode result = CURLE_OUT_OF_MEMORY; - DEBUGASSERT(method); - if(m_len + 1 > sizeof(req->method)) - return CURLE_BAD_FUNCTION_ARGUMENT; + DEBUGASSERT(method && m_len); - req = calloc(1, sizeof(*req)); + req = calloc(1, sizeof(*req) + m_len); if(!req) goto out; memcpy(req->method, method, m_len); @@ -4394,11 +4392,9 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, CURLcode result = CURLE_OUT_OF_MEMORY; CURLUcode uc; - DEBUGASSERT(method); - if(m_len + 1 > sizeof(req->method)) - return CURLE_BAD_FUNCTION_ARGUMENT; + DEBUGASSERT(method && m_len); - req = calloc(1, sizeof(*req)); + req = calloc(1, sizeof(*req) + m_len); if(!req) goto out; memcpy(req->method, method, m_len); diff --git a/lib/http.h b/lib/http.h index 66abdbd201..ba7a121d09 100644 --- a/lib/http.h +++ b/lib/http.h @@ -218,12 +218,12 @@ CURLcode Curl_http_decode_status(int *pstatus, const char *s, size_t len); * All about a core HTTP request, excluding body and trailers */ struct httpreq { - char method[24]; + struct dynhds headers; + struct dynhds trailers; char *scheme; char *authority; char *path; - struct dynhds headers; - struct dynhds trailers; + char method[1]; }; /** -- 2.47.3