]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http1: parse header from uint8_t buffer
authorStefan Eissing <stefan@eissing.org>
Fri, 28 Nov 2025 09:25:59 +0000 (10:25 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 28 Nov 2025 15:07:07 +0000 (16:07 +0100)
To save casting the passed buffer when parsing HTTP/1 request
headers from an uint8_t buffer.

Closes #19742

lib/http1.c
lib/http1.h
lib/http2.c
lib/vquic/curl_ngtcp2.c
lib/vquic/curl_osslq.c
lib/vquic/curl_quiche.c
tests/unit/unit2603.c

index 0a80fedfc722f9e0d4c68d55043a8a9b6890e3fb..657a674105fa4ce807ae283c15a26434b6e99929 100644 (file)
@@ -77,7 +77,7 @@ static CURLcode trim_line(struct h1_req_parser *parser, int options)
 }
 
 static CURLcode detect_line(struct h1_req_parser *parser,
-                            const char *buf, const size_t buflen,
+                            const uint8_t *buf, const size_t buflen,
                             size_t *pnread)
 {
   const char *line_end;
@@ -87,14 +87,14 @@ static CURLcode detect_line(struct h1_req_parser *parser,
   line_end = memchr(buf, '\n', buflen);
   if(!line_end)
     return CURLE_AGAIN;
-  parser->line = buf;
-  parser->line_len = line_end - buf + 1;
+  parser->line = (const char *)buf;
+  parser->line_len = line_end - parser->line + 1;
   *pnread = parser->line_len;
   return CURLE_OK;
 }
 
 static CURLcode next_line(struct h1_req_parser *parser,
-                          const char *buf, const size_t buflen, int options,
+                          const uint8_t *buf, const size_t buflen, int options,
                           size_t *pnread)
 {
   CURLcode result;
@@ -262,7 +262,7 @@ out:
 }
 
 CURLcode Curl_h1_req_parse_read(struct h1_req_parser *parser,
-                                const char *buf, size_t buflen,
+                                const uint8_t *buf, size_t buflen,
                                 const char *scheme_default,
                                 const char *custom_method,
                                 int options, size_t *pnread)
index 944e9038dd986083084baa4cc196dffefa17e684..88bd99798e055f0bf886653b44bbe321f455191c 100644 (file)
@@ -49,7 +49,7 @@ void Curl_h1_req_parse_init(struct h1_req_parser *parser, size_t max_line_len);
 void Curl_h1_req_parse_free(struct h1_req_parser *parser);
 
 CURLcode Curl_h1_req_parse_read(struct h1_req_parser *parser,
-                                const char *buf, size_t buflen,
+                                const uint8_t *buf, size_t buflen,
                                 const char *scheme_default,
                                 const char *custom_method,
                                 int options, size_t *pnread);
index baaefd439d4feb83982752875076f24dd9b4df01..e75d7431e72c543b0fd01bd6da17a8138bdf6272 100644 (file)
@@ -2277,7 +2277,7 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream,
   if(result)
     goto out;
 
-  result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, len, NULL,
+  result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL,
                                   !data->state.http_ignorecustom ?
                                   data->set.str[STRING_CUSTOMREQUEST] : NULL,
                                   0, &nwritten);
index 4767780a922d5d6d7ab107af084aad34093bdaa2..62255285b6a0995c492ae9cf61e736cc16f5099f 100644 (file)
@@ -1548,7 +1548,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf,
     goto out;
   }
 
-  result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, len, NULL,
+  result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL,
                                   !data->state.http_ignorecustom ?
                                   data->set.str[STRING_CUSTOMREQUEST] : NULL,
                                   0, pnwritten);
index 1c3f0c55b66e7f6d03145508bd8903c784fec250..7bca97b4086db7ae04d0a6cf278cf4d27a9b502e 100644 (file)
@@ -1900,7 +1900,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf,
     goto out;
   }
 
-  result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, len, NULL,
+  result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL,
                                   !data->state.http_ignorecustom ?
                                   data->set.str[STRING_CUSTOMREQUEST] : NULL,
                                   0, pnwritten);
index c182e1490d237a6927e6138e9c64c20e2bf39e8d..5aca750c2cb9a4f42c85a9c869308082858cd426 100644 (file)
@@ -976,7 +976,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf,
 
   DEBUGASSERT(stream);
 
-  result = Curl_h1_req_parse_read(&stream->h1, (const char *)buf, blen, NULL,
+  result = Curl_h1_req_parse_read(&stream->h1, buf, blen, NULL,
                                     !data->state.http_ignorecustom ?
                                     data->set.str[STRING_CUSTOMREQUEST] : NULL,
                                     0, pnwritten);
index 61295de37e1ddfc15aa2430f789701325e50f6c8..1de774d26f8b413855e81019b189ba62df0ed706 100644 (file)
@@ -63,7 +63,7 @@ struct tcase {
 static void parse_success(const struct tcase *t)
 {
   struct h1_req_parser p;
-  const char *buf;
+  const uint8_t *buf;
   size_t buflen, i, in_len, in_consumed;
   CURLcode err;
   size_t nread;
@@ -71,8 +71,8 @@ static void parse_success(const struct tcase *t)
   Curl_h1_req_parse_init(&p, 1024);
   in_len = in_consumed = 0;
   for(i = 0; t->input[i]; ++i) {
-    buf = t->input[i];
-    buflen = strlen(buf);
+    buf = (const uint8_t *)t->input[i];
+    buflen = strlen(t->input[i]);
     in_len += buflen;
     err = Curl_h1_req_parse_read(&p, buf, buflen, t->default_scheme,
                                  t->custom_method, 0, &nread);