]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mxu-h1: Report a parsing error on abort with pending data
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Mar 2023 15:04:23 +0000 (16:04 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Mar 2023 16:35:16 +0000 (17:35 +0100)
When an abort is detected before all headers were received, and if there are
pending incoming data, we must report a parsing error instead of a
connection abort. This way it will be able to be handled as an invalid
message by HTTP analyzers instead of an early abort with no message.

It is especially important to be accurate on L7 retry. Indeed, without this
fix, this case will be handle by the "empty-response" retries policy while a
retry on "junk-response" is more accurate.

This patch must be backported to 2.7.

src/mux_h1.c

index 7517d92f97bd5a9977b2a6ba360a651226f2a4da..4b071f80ba5e5e1c600e683a549672cf4fa2702c 100644 (file)
@@ -1912,9 +1912,16 @@ static size_t h1_process_demux(struct h1c *h1c, struct buffer *buf, size_t count
                                se_fl_set(h1s->sd, SE_FL_EOI);
                                TRACE_STATE("report EOI to SE", H1_EV_RX_DATA, h1c->conn, h1s);
                        }
-                       else if (h1m->state < H1_MSG_DONE && (h1m->state != H1_MSG_RPBEFORE || b_data(&h1c->ibuf))) {
-                               se_fl_set(h1s->sd, SE_FL_ERROR);
-                               TRACE_ERROR("message aborted, set error on SC", H1_EV_RX_DATA|H1_EV_H1S_ERR, h1c->conn, h1s);
+                       else if (h1m->state < H1_MSG_DONE) {
+                               if (h1m->state > H1_MSG_LAST_LF) {
+                                       se_fl_set(h1s->sd, SE_FL_ERROR);
+                                       TRACE_ERROR("message aborted, set error on SC", H1_EV_RX_DATA|H1_EV_H1S_ERR, h1c->conn, h1s);
+                               }
+                               else if (b_data(&h1c->ibuf)) {
+                                       htx->flags |= HTX_FL_PARSING_ERROR;
+                                       TRACE_ERROR("truncated message, set error on SC", H1_EV_RX_DATA|H1_EV_H1S_ERR, h1c->conn, h1s);
+                               }
+                               /* Otherwise (no data was never received) don't report any error just EOS */
                        }
 
                        if (h1s->flags & H1S_F_TX_BLK) {