]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h3: check return values of htx_add_* on headers parsing
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 15 Dec 2022 09:58:05 +0000 (10:58 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 15 Dec 2022 10:48:30 +0000 (11:48 +0100)
Check return values of htx_add_header()/htx_add_eof() during H3 HEADERS
conversion to HTX. In case of error, the connection is interrupted with
a CONNECTION_CLOSE.

This commit is useful to detect abnormal situation on headers parsing.
It should be backported up to 2.7.

src/h3.c

index c9e6bbb3914b7736add3a9f9a10233fe98834f7b..8912fa5d9d51a5f65221fc7f08c4f13820f8ddb1 100644 (file)
--- a/src/h3.c
+++ b/src/h3.c
@@ -529,8 +529,13 @@ static ssize_t h3_headers_to_htx(struct qcs *qcs, const struct buffer *buf,
 
        sl->info.req.meth = find_http_meth(meth.ptr, meth.len);
 
-       if (isttest(authority))
-               htx_add_header(htx, ist("host"), authority);
+       if (isttest(authority)) {
+               if (!htx_add_header(htx, ist("host"), authority)) {
+                       h3c->err = H3_INTERNAL_ERROR;
+                       len = -1;
+                       goto out;
+               }
+       }
 
        /* now treat standard headers */
        while (1) {
@@ -582,7 +587,11 @@ static ssize_t h3_headers_to_htx(struct qcs *qcs, const struct buffer *buf,
                        }
                }
 
-               htx_add_header(htx, list[hdr_idx].n, list[hdr_idx].v);
+               if (!htx_add_header(htx, list[hdr_idx].n, list[hdr_idx].v)) {
+                       h3c->err = H3_INTERNAL_ERROR;
+                       len = -1;
+                       goto out;
+               }
                ++hdr_idx;
        }
 
@@ -594,7 +603,12 @@ static ssize_t h3_headers_to_htx(struct qcs *qcs, const struct buffer *buf,
                }
        }
 
-       htx_add_endof(htx, HTX_BLK_EOH);
+       if (!htx_add_endof(htx, HTX_BLK_EOH)) {
+               h3c->err = H3_INTERNAL_ERROR;
+               len = -1;
+               goto out;
+       }
+
        if (fin)
                htx->flags |= HTX_FL_EOM;