From 9af89f79057084bf8e7f4900333fda187475ca4a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 26 Sep 2015 11:50:08 +0200 Subject: [PATCH] BUG/MEDIUM: lua: better fix for the protocol check 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 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index e34658c3a..d2a211078 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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; }