]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mux-h1: Properly catch parsing errors on payload and trailers
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 15 Nov 2019 08:36:28 +0000 (09:36 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 15 Nov 2019 13:24:06 +0000 (14:24 +0100)
Errors during the payload or the trailers parsing are reported with the
HTX_FL_PARSING_ERROR flag on the HTX message and not a negative return
value. This change was introduced when the fonctions to convert an H1 message to
HTX one were moved to a dedicated file. But the h1 mux was not fully updated
accordingly.

No backport needed except if the commits about file h1_htx.c are backported.

src/mux_h1.c

index c47db476db0169893620135e1098b83f72ca8c14..4a254ddb92e13b23ac6a8ef7c8b8abd70748c02a 100644 (file)
@@ -1242,9 +1242,9 @@ static size_t h1_process_data(struct h1s *h1s, struct h1m *h1m, struct htx **htx
 
        TRACE_ENTER(H1_EV_RX_DATA|H1_EV_RX_BODY, h1s->h1c->conn, h1s,, (size_t[]){max});
        ret = h1_parse_msg_data(h1m, htx, buf, *ofs, max, htxbuf);
-       if (ret <= 0) {
+       if (!ret) {
                TRACE_DEVEL("leaving on missing data or error", H1_EV_RX_DATA|H1_EV_RX_BODY, h1s->h1c->conn, h1s);
-               if (ret < 0) {
+               if ((*htx)->flags & HTX_FL_PARSING_ERROR) {
                        if (!(h1m->flags & H1_MF_RESP)) {
                                h1s->flags |= H1S_F_REQ_ERROR;
                                TRACE_USER("rejected H1 request", H1_EV_RX_DATA|H1_EV_RX_BODY|H1_EV_H1S_ERR, h1s->h1c->conn, h1s);
@@ -1257,15 +1257,17 @@ static size_t h1_process_data(struct h1s *h1s, struct h1m *h1m, struct htx **htx
                        TRACE_STATE("parsing error", H1_EV_RX_DATA|H1_EV_RX_BODY|H1_EV_H1S_ERR, h1s->h1c->conn, h1s);
                        h1_capture_bad_message(h1s->h1c, h1s, h1m, buf);
                }
-               return 0;
+               goto end;
        }
 
+       *ofs += ret;
+
+  end:
        if (h1m->state == H1_MSG_DONE) {
                h1s->cs->flags |= CS_FL_EOI;
                TRACE_STATE("end of message", H1_EV_RX_DATA|H1_EV_RX_BODY|H1_EV_RX_EOI, h1s->h1c->conn);
        }
 
-       *ofs += ret;
        TRACE_LEAVE(H1_EV_RX_DATA|H1_EV_RX_BODY, h1s->h1c->conn, h1s,, (size_t[]){ret});
        return ret;
 }
@@ -1283,9 +1285,9 @@ static size_t h1_process_trailers(struct h1s *h1s, struct h1m *h1m, struct htx *
 
        TRACE_ENTER(H1_EV_RX_DATA|H1_EV_RX_TLRS, h1s->h1c->conn, h1s,, (size_t[]){max});
        ret = h1_parse_msg_tlrs(h1m, htx, buf, *ofs, max);
-       if (ret <= 0) {
+       if (!ret) {
                TRACE_DEVEL("leaving on missing data or error", H1_EV_RX_DATA|H1_EV_RX_BODY, h1s->h1c->conn, h1s);
-               if (ret < 0) {
+               if (htx->flags & HTX_FL_PARSING_ERROR) {
                        if (!(h1m->flags & H1_MF_RESP)) {
                                h1s->flags |= H1S_F_REQ_ERROR;
                                TRACE_USER("rejected H1 request", H1_EV_RX_DATA|H1_EV_RX_TLRS|H1_EV_H1S_ERR, h1s->h1c->conn, h1s);
@@ -1298,11 +1300,13 @@ static size_t h1_process_trailers(struct h1s *h1s, struct h1m *h1m, struct htx *
                        TRACE_STATE("parsing error", H1_EV_RX_DATA|H1_EV_RX_TLRS|H1_EV_H1S_ERR, h1s->h1c->conn, h1s);
                        h1_capture_bad_message(h1s->h1c, h1s, h1m, buf);
                }
-               return 0;
+               goto end;
        }
 
        *ofs += ret;
        h1s->flags |= H1S_F_HAVE_I_TLR;
+
+  end:
        TRACE_LEAVE(H1_EV_RX_DATA|H1_EV_RX_TLRS, h1s->h1c->conn, h1s,, (size_t[]){ret});
        return ret;
 }