]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h2: Don't tests the start-line when sending HEADERS frame
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 29 Jan 2021 10:39:43 +0000 (11:39 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 29 Jan 2021 12:27:57 +0000 (13:27 +0100)
When a HEADERS frame is sent, it is always when an HTX start-line block is
found. Thus, in h2s_bck_make_req_headers() and h2s_frt_make_resp_headers()
functions, it is useless to tests the start-line. Instead of being too
defensive, we use BUG_ON() now because it must not happen and must be
handled as a bug.

This patch should fix the issue #1086.

src/mux_h2.c

index 55c08f74bad85cb3aa7cbf7094a9d4b1ff41362a..6b7f3e9d6039e0d2bda1acfcfb36951d4fc97d7a 100644 (file)
@@ -4943,10 +4943,7 @@ static size_t h2s_frt_make_resp_headers(struct h2s *h2s, struct htx *htx)
                        break;
 
                if (type == HTX_BLK_HDR) {
-                       if (!sl) {
-                               TRACE_ERROR("no start-line", H2_EV_TX_FRAME|H2_EV_TX_HDR|H2_EV_H2S_ERR, h2c->conn, h2s);
-                               goto fail;
-                       }
+                       BUG_ON(!sl); /* The start-line mut be defined before any headers */
                        if (unlikely(hdr >= sizeof(list)/sizeof(list[0]) - 1)) {
                                TRACE_ERROR("too many headers", H2_EV_TX_FRAME|H2_EV_TX_HDR|H2_EV_H2S_ERR, h2c->conn, h2s);
                                goto fail;
@@ -4957,10 +4954,7 @@ static size_t h2s_frt_make_resp_headers(struct h2s *h2s, struct htx *htx)
                        hdr++;
                }
                else if (type == HTX_BLK_RES_SL) {
-                       if (sl) {
-                               TRACE_PROTO("multiple start-lines", H2_EV_TX_FRAME|H2_EV_TX_HDR|H2_EV_H2S_ERR, h2c->conn, h2s);
-                               goto fail;
-                       }
+                       BUG_ON(sl); /* Only one start-line expected */
                        sl = htx_get_blk_ptr(htx, blk);
                        h2s->status = sl->info.res.status;
                        if (h2s->status == 204 || h2s->status == 304)
@@ -4993,6 +4987,9 @@ static size_t h2s_frt_make_resp_headers(struct h2s *h2s, struct htx *htx)
                }
        }
 
+       /* The start-line me be defined */
+       BUG_ON(!sl);
+
        /* marker for end of headers */
        list[hdr].n = ist("");
 
@@ -5183,10 +5180,7 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
                        break;
 
                if (type == HTX_BLK_REQ_SL) {
-                       if (sl) {
-                               TRACE_ERROR("multiple start-lines", H2_EV_TX_FRAME|H2_EV_TX_HDR|H2_EV_H2S_ERR, h2c->conn, h2s);
-                               goto fail;
-                       }
+                       BUG_ON(sl); /* Only one start-line expected */
                        sl = htx_get_blk_ptr(htx, blk);
                        meth = htx_sl_req_meth(sl);
                        uri  = htx_sl_req_uri(sl);
@@ -5198,10 +5192,7 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
                        }
                }
                else if (type == HTX_BLK_HDR) {
-                       if (!sl) {
-                               TRACE_ERROR("no start-line", H2_EV_TX_FRAME|H2_EV_TX_HDR|H2_EV_H2S_ERR, h2c->conn, h2s);
-                               goto fail;
-                       }
+                       BUG_ON(!sl); /* The start-line mut be defined before any headers */
                        if (unlikely(hdr >= sizeof(list)/sizeof(list[0]) - 1)) {
                                TRACE_ERROR("too many headers", H2_EV_TX_FRAME|H2_EV_TX_HDR|H2_EV_H2S_ERR, h2c->conn, h2s);
                                goto fail;
@@ -5256,6 +5247,9 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
                }
        }
 
+       /* The start-line me be defined */
+       BUG_ON(!sl);
+
        /* Now add the server name to a header (if requested) */
        if ((h2c->flags & H2_CF_IS_BACK) && h2c->proxy->server_id_hdr_name) {
                struct server *srv = objt_server(h2c->conn->target);