]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: lua: better fix for the protocol check
authorWilly Tarreau <w@1wt.eu>
Sat, 26 Sep 2015 09:50:08 +0000 (11:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 26 Sep 2015 09:50:08 +0000 (11:50 +0200)
Commit d75cb0f ("BUG/MAJOR: lua: segfault after the channel data is
modified by some Lua action.") introduced a regression causing an
action run from a TCP rule in an HTTP proxy to end in HTTP error
if it terminated cleanly, because it didn't parse the HTTP request!

Relax the test so that it takes into account the opportunity for the
analysers to parse the message.

src/hlua.c

index e34658c3a9bfb64a4eaeb9c7073292d5905a9db0..d2a2110783cab543f3ef631825f78941c8228a95 100644 (file)
@@ -2403,15 +2403,22 @@ static int hlua_check_proto(struct stream *stream, int dir)
 {
        const struct chunk msg = { .len = 0 };
 
-       /* Protocol HTTP. The message parsing state must be in accord
-        * with the request or response state.
+       /* Protocol HTTP. The message parsing state must match the request or
+        * response state. The problem that may happen is that Lua modifies
+        * the request or response message *after* it was parsed, and corrupted
+        * it so that it could not be processed anymore. We just need to verify
+        * if the parser is still expected to run or not.
         */
        if (stream->be->mode == PR_MODE_HTTP) {
-               if (dir == 0 && stream->txn->req.msg_state < HTTP_MSG_BODY) {
+               if (dir == 0 &&
+                   !(stream->req.analysers & AN_REQ_WAIT_HTTP) &&
+                   stream->txn->req.msg_state < HTTP_MSG_BODY) {
                        stream_int_retnclose(&stream->si[0], &msg);
                        return 0;
                }
-               else if (dir == 1 && stream->txn->rsp.msg_state < HTTP_MSG_BODY) {
+               else if (dir == 1 &&
+                        !(stream->res.analysers & AN_RES_WAIT_HTTP) &&
+                        stream->txn->rsp.msg_state < HTTP_MSG_BODY) {
                        stream_int_retnclose(&stream->si[0], &msg);
                        return 0;
                }