]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: filters: Properly set the HTTP status code on analysis error
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Sep 2019 13:24:55 +0000 (15:24 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 10 Sep 2019 08:29:54 +0000 (10:29 +0200)
When a filter returns an error during the HTTP analysis, an error must be
returned if the status code is not already set. On the request path, an error
400 is returned. On the response path, an error 502 is returned. The status is
considered as unset if its value is not strictly positive.

If needed, this patch may be backported to all versions having filters (as far
as 1.7). Because nobody have never report any bug, the backport to 2.0 is
probably enough.

src/filters.c

index 0119205aef038ce0e7b73a14dad77f9315dfcf63..f02f45b0057fcdfc02babcf6855fc5687ec31254 100644 (file)
@@ -982,6 +982,7 @@ handle_analyzer_result(struct stream *s, struct channel *chn,
                       unsigned int an_bit, int ret)
 {
        int finst;
+       int status = 0;
 
        if (ret < 0)
                goto return_bad_req;
@@ -1003,21 +1004,23 @@ handle_analyzer_result(struct stream *s, struct channel *chn,
        if (!(chn->flags & CF_ISRESP)) {
                s->req.analysers &= AN_REQ_FLT_END;
                finst = SF_FINST_R;
+               status = 400;
                /* FIXME: incr counters */
        }
        else {
                s->res.analysers &= AN_RES_FLT_END;
                finst = SF_FINST_H;
+               status = 502;
                /* FIXME: incr counters */
        }
 
        if (IS_HTX_STRM(s)) {
                /* Do not do that when we are waiting for the next request */
-               if (s->txn->status)
+               if (s->txn->status > 0)
                        http_reply_and_close(s, s->txn->status, NULL);
                else {
-                       s->txn->status = 400;
-                       http_reply_and_close(s, 400, http_error_message(s));
+                       s->txn->status = status;
+                       http_reply_and_close(s, status, http_error_message(s));
                }
        }