changeset 8409:26cb2f3259b1 quic

HTTP/3: reallocate strings inserted into the dynamic table. They should always be allocated from the main QUIC connection pool.
author Roman Arutyunyan <arut@nginx.com>
date Thu, 14 May 2020 16:02:32 +0300
parents 5b367070cc9c
children c7d1b500bd0a
files src/http/v3/ngx_http_v3_tables.c
diffstat 1 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/v3/ngx_http_v3_tables.c
+++ b/src/http/v3/ngx_http_v3_tables.c
@@ -149,12 +149,15 @@ ngx_http_v3_ref_insert(ngx_connection_t 
     ngx_uint_t index, ngx_str_t *value)
 {
     ngx_array_t           *dt;
+    ngx_connection_t      *pc;
     ngx_http_v3_header_t  *ref, *h;
 
     ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http3 ref insert %s[$ui] \"%V\"",
                    dynamic ? "dynamic" : "static", index, value);
 
+    pc = c->qs->parent;
+
     ref = ngx_http_v3_lookup_table(c, dynamic, index);
     if (ref == NULL) {
         return NGX_ERROR;
@@ -171,7 +174,14 @@ ngx_http_v3_ref_insert(ngx_connection_t 
     }
 
     h->name = ref->name;
-    h->value = *value;
+
+    h->value.data = ngx_pstrdup(pc->pool, value);
+    if (h->value.data == NULL) {
+        h->value.len = 0;
+        return NGX_ERROR;
+    }
+
+    h->value.len = value->len;
 
     if (ngx_http_v3_new_header(c) != NGX_OK) {
         return NGX_ERROR;
@@ -186,11 +196,14 @@ ngx_http_v3_insert(ngx_connection_t *c, 
     ngx_str_t *value)
 {
     ngx_array_t           *dt;
+    ngx_connection_t      *pc;
     ngx_http_v3_header_t  *h;
 
     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http3 insert \"%V\":\"%V\"", name, value);
 
+    pc = c->qs->parent;
+
     dt = ngx_http_v3_get_dynamic_table(c);
     if (dt == NULL) {
         return NGX_ERROR;
@@ -201,8 +214,22 @@ ngx_http_v3_insert(ngx_connection_t *c, 
         return NGX_ERROR;
     }
 
-    h->name = *name;
-    h->value = *value;
+    h->name.data = ngx_pstrdup(pc->pool, name);
+    if (h->name.data == NULL) {
+        h->name.len = 0;
+        h->value.len = 0;
+        return NGX_ERROR;
+    }
+
+    h->name.len = name->len;
+
+    h->value.data = ngx_pstrdup(pc->pool, value);
+    if (h->value.data == NULL) {
+        h->value.len = 0;
+        return NGX_ERROR;
+    }
+
+    h->value.len = value->len;
 
     if (ngx_http_v3_new_header(c) != NGX_OK) {
         return NGX_ERROR;