]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hq_interop: Stop BUG_ON() truncated streams
authorFrédéric Lécaille <flecaille@haproxy.com>
Wed, 15 Dec 2021 21:38:48 +0000 (22:38 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 17 Dec 2021 07:38:43 +0000 (08:38 +0100)
This is required if we do not want to make haproxy crash during zerortt
interop runner test which makes a client open multiple streams with
long request paths.

src/hq_interop.c

index 9af937f700690d3a41252bed9a5f89bde1db206d..8271196060ad3573985556430f50119f3ed57c21 100644 (file)
@@ -17,23 +17,48 @@ static int hq_interop_decode_qcs(struct qcs *qcs, int fin, void *ctx)
        struct conn_stream *cs;
        struct buffer htx_buf = BUF_NULL;
        struct ist path;
-       char *ptr;
+       char *ptr = b_head(rxbuf);
+       char *end = b_wrap(rxbuf);
+       size_t size = b_size(rxbuf);
+       size_t data = b_data(rxbuf);
 
        b_alloc(&htx_buf);
        htx = htx_from_buf(&htx_buf);
 
        /* skip method */
-       ptr = b_orig(rxbuf);
-       while (HTTP_IS_TOKEN(*ptr))
-               ++ptr;
-       BUG_ON(!HTTP_IS_SPHT(*ptr));
-       ++ptr;
+       while (data && HTTP_IS_TOKEN(*ptr)) {
+               if (++ptr == end)
+                       ptr -= size;
+               data--;
+       }
+
+       if (!data || !HTTP_IS_SPHT(*ptr)) {
+               fprintf(stderr, "truncated stream\n");
+               return 0;
+       }
+
+       if (++ptr == end)
+               ptr -= size;
+
+       if (!--data) {
+               fprintf(stderr, "truncated stream\n");
+               return 0;
+       }
 
        /* extract path */
        BUG_ON(HTTP_IS_LWS(*ptr));
        path.ptr = ptr;
-       while (!HTTP_IS_LWS(*ptr))
-               ++ptr;
+       while (data && !HTTP_IS_LWS(*ptr)) {
+               if (++ptr == end)
+                       ptr -= size;
+               data--;
+       }
+
+       if (!data) {
+               fprintf(stderr, "truncated stream\n");
+               return 0;
+       }
+
        BUG_ON(!HTTP_IS_LWS(*ptr));
        path.len = ptr - path.ptr;