]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: h1-htx: report the trailer parsing error position master
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 30 Nov 2026 15:31:05 +0000 (16:31 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 30 Nov 2026 15:32:07 +0000 (16:32 +0100)
Trailer parsing uses a dedicated h1m (tlr_h1m) whose err_pos is relative to
the start of the trailers in the source buffer, i.e. to the offset passed
to h1_parse_msg_tlrs(). On a parsing error the main message's err_pos was
set to h1m->next, the chunk-parsing position, so the error snapshot taken
by h1_capture_bad_message() pointed to the wrong location.

h1_parse_msg_tlrs() now seeds tlr_h1m.err_pos with -1 or -2 depending on
the caller's leniency instead of copying h1m->err_pos. This way a stale
non-negative err_pos left over from a tolerated violation in the main
message headers can no longer suppress the trailer parser's capture (all
capture branches in h1_headers_to_hdr_list() are gated on err_pos == -1),
and it cannot be leaked back into the main message either.

On error, when the trailer parser pinpointed the faulty byte, the main
message's err_pos is now set to ofs + tlr_h1m.err_pos, i.e. the position
in the source buffer. Otherwise the previous behavior (h1m->next) is kept
as the fallback. This mirrors what h1_parse_msg_hdrs() already does for
headers via h1m->next, and makes mux_h1/mux_fcgi capture the correct
position for the H1_MSG_TRAILERS state.

No backport needed, this only affects error snapshots reporting.

src/h1_htx.c

index 6720d7cf458ea1eb14e01c54018f985d7ef2cb09..18501e2f58b6b0d2d31947a3a42f42d1be1fcdcf 100644 (file)
@@ -1037,7 +1037,7 @@ int h1_parse_msg_tlrs(struct h1m *h1m, struct htx *dsthtx,
 
        tlr_h1m.state = H1_MSG_TRAILERS;
        tlr_h1m.flags = (H1_MF_NO_PHDR|H1_MF_HDRS_ONLY);
-       tlr_h1m.err_pos = h1m->err_pos;
+       tlr_h1m.err_pos = (h1m->err_pos >= -1) ? -1 : -2; /* keep caller's leniency; see h1_headers_to_hdr_list() */
        /* The buffer was realigned above, so <b_stop()> safely points to the
         * byte following the end of the data. Note that b_tail() must not be
         * used instead: it wraps to the buffer's origin when the data end
@@ -1077,7 +1077,7 @@ int h1_parse_msg_tlrs(struct h1m *h1m, struct htx *dsthtx,
        return -2;
   error:
        h1m->err_state = h1m->state;
-       h1m->err_pos = h1m->next;
+       h1m->err_pos = (tlr_h1m.err_pos >= 0) ? ofs + tlr_h1m.err_pos : h1m->next;
        dsthtx->flags |= HTX_FL_PARSING_ERROR;
        return -1;
 }