http: fix path formatting in request templates 31/43231/3
authorMatus Fabian <[email protected]>
Fri, 20 Jun 2025 13:30:28 +0000 (13:30 +0000)
committerFlorin Coras <[email protected]>
Fri, 20 Jun 2025 20:51:09 +0000 (20:51 +0000)
Client app pass path as data bytes and length, not null terminated
string. Fix also msg.data.target_path_len value in http client and http
cli client, set it to string length not vec_len.

Type: fix

Change-Id: Icab6d830812bbfc2e6df82564d6d087476769111
Signed-off-by: Matus Fabian <[email protected]>
src/plugins/hs_apps/http_client.c
src/plugins/hs_apps/http_client_cli.c
src/plugins/http/http1.c

index 937d98e..0137f88 100644 (file)
@@ -190,8 +190,9 @@ hc_request (session_t *s, hc_worker_t *wrk, hc_session_t *hc_session,
   rv = svm_fifo_enqueue (s->tx_fifo, sizeof (wrk->msg), (u8 *) &wrk->msg);
   ASSERT (rv == sizeof (wrk->msg));
 
-  rv = svm_fifo_enqueue (s->tx_fifo, vec_len (hcm->target), hcm->target);
-  ASSERT (rv == vec_len (hcm->target));
+  rv =
+    svm_fifo_enqueue (s->tx_fifo, wrk->msg.data.target_path_len, hcm->target);
+  ASSERT (rv == wrk->msg.data.target_path_len);
 
   rv = svm_fifo_enqueue (s->tx_fifo, wrk->req_headers.tail_offset,
                         wrk->headers_buf);
@@ -308,8 +309,8 @@ hc_session_connected_callback (u32 app_index, u32 hc_session_index,
        wrk->msg.data.body_len = 0;
 
       wrk->msg.type = HTTP_MSG_REQUEST;
-      /* request target */
-      wrk->msg.data.target_path_len = vec_len (hcm->target);
+      /* request target len must be without null termination */
+      wrk->msg.data.target_path_len = strlen ((char *) hcm->target);
       /* custom headers */
       wrk->msg.data.headers_len = wrk->req_headers.tail_offset;
       /* total length */
index b72d4df..f8984be 100644 (file)
@@ -167,7 +167,8 @@ hcc_ts_connected_callback (u32 app_index, u32 hc_index, session_t *as,
   msg.method_type = HTTP_REQ_GET;
   /* request target */
   msg.data.target_path_offset = 0;
-  msg.data.target_path_len = vec_len (hcm->http_query);
+  /* request target len must be without null termination */
+  msg.data.target_path_len = strlen ((char *) hcm->http_query);
   /* custom headers */
   msg.data.headers_offset = msg.data.target_path_len;
   msg.data.headers_len = headers.tail_offset;
@@ -179,7 +180,7 @@ hcc_ts_connected_callback (u32 app_index, u32 hc_index, session_t *as,
     msg.data.target_path_len + msg.data.headers_len + msg.data.body_len;
 
   svm_fifo_seg_t segs[3] = { { (u8 *) &msg, sizeof (msg) },
-                            { hcm->http_query, vec_len (hcm->http_query) },
+                            { hcm->http_query, msg.data.target_path_len },
                             { headers_buf, msg.data.headers_len } };
 
   rv = svm_fifo_enqueue_segments (as->tx_fifo, segs, 3, 0 /* allow partial */);
index 106a1fd..e7ddaf3 100644 (file)
@@ -46,22 +46,22 @@ static const char *connection_upgrade_template = "Connection: upgrade\r\n"
 /**
  * http request boilerplate
  */
-static const char *get_request_template = "GET %s HTTP/1.1\r\n"
+static const char *get_request_template = "GET %U HTTP/1.1\r\n"
                                          "Host: %v\r\n"
                                          "User-Agent: %v\r\n";
 
-static const char *post_request_template = "POST %s HTTP/1.1\r\n"
+static const char *post_request_template = "POST %U HTTP/1.1\r\n"
                                           "Host: %v\r\n"
                                           "User-Agent: %v\r\n"
                                           "Content-Length: %llu\r\n";
 
-static const char *put_request_template = "PUT %s HTTP/1.1\r\n"
+static const char *put_request_template = "PUT %U HTTP/1.1\r\n"
                                          "Host: %v\r\n"
                                          "User-Agent: %v\r\n"
                                          "Content-Length: %llu\r\n";
 
 static const char *put_chunked_request_template =
-  "PUT %s HTTP/1.1\r\n"
+  "PUT %U HTTP/1.1\r\n"
   "Host: %v\r\n"
   "User-Agent: %v\r\n"
   "Transfer-Encoding: chunked\r\n";
@@ -1411,7 +1411,7 @@ http1_req_state_wait_app_method (http_conn_t *hc, http_req_t *req,
        */
       request = format (request, get_request_template,
                        /* target */
-                       target,
+                       format_http_bytes, target, msg.data.target_path_len,
                        /* Host */
                        hc->host,
                        /* User-Agent */
@@ -1435,7 +1435,7 @@ http1_req_state_wait_app_method (http_conn_t *hc, http_req_t *req,
        */
       request = format (request, post_request_template,
                        /* target */
-                       target,
+                       format_http_bytes, target, msg.data.target_path_len,
                        /* Host */
                        hc->host,
                        /* User-Agent */
@@ -1456,13 +1456,14 @@ http1_req_state_wait_app_method (http_conn_t *hc, http_req_t *req,
          /*
           * Streaming PUT with chunked transfer encoding
           */
-         request = format (request, put_chunked_request_template,
-                           /* target */
-                           target,
-                           /* Host */
-                           hc->host,
-                           /* User-Agent */
-                           hc->app_name);
+         request =
+           format (request, put_chunked_request_template,
+                   /* target */
+                   format_http_bytes, target, msg.data.target_path_len,
+                   /* Host */
+                   hc->host,
+                   /* User-Agent */
+                   hc->app_name);
 
          http_req_tx_buffer_init (req, &msg);
 
@@ -1480,15 +1481,16 @@ http1_req_state_wait_app_method (http_conn_t *hc, http_req_t *req,
          /*
           * Regular PUT with Content-Length
           */
-         request = format (request, put_request_template,
-                           /* target */
-                           target,
-                           /* Host */
-                           hc->host,
-                           /* User-Agent */
-                           hc->app_name,
-                           /* Content-Length */
-                           msg.data.body_len);
+         request =
+           format (request, put_request_template,
+                   /* target */
+                   format_http_bytes, target, msg.data.target_path_len,
+                   /* Host */
+                   hc->host,
+                   /* User-Agent */
+                   hc->app_name,
+                   /* Content-Length */
+                   msg.data.body_len);
 
          http_req_tx_buffer_init (req, &msg);