]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cli: don't call the kw->io_release if kw->parse failed
authorWilliam Lallemand <wlallemand@haproxy.com>
Fri, 25 Oct 2019 19:10:14 +0000 (21:10 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Fri, 25 Oct 2019 20:00:49 +0000 (22:00 +0200)
The io_release() callback of the cli_kw is supposed to be used to clean
what an io_handler() has made. It is called once the work in the IO
handler is finished, or when the connection was aborted by the client.

This patch fixes a bug where the io_release callback was called even
when the parse() callback failed. Which means that the io_release() could
called even if the io_handler() was not called.

Should be backported in every versions that have a cli_kw->release().
(as far as 1.7)

src/cli.c

index 6037e9698bdf03545d06c3fe8ae2b687d1781bf1..db695d5fd38d3652ab75f7b5f879842ec817ec4f 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -577,10 +577,19 @@ static int cli_parse_request(struct appctx *appctx)
 
        appctx->io_handler = kw->io_handler;
        appctx->io_release = kw->io_release;
-       /* kw->parse could set its own io_handler or ip_release handler */
-       if ((!kw->parse || kw->parse(args, payload, appctx, kw->private) == 0) && appctx->io_handler) {
-               appctx->st0 = CLI_ST_CALLBACK;
-       }
+
+       if (kw->parse && kw->parse(args, payload, appctx, kw->private) != 0)
+               goto fail;
+
+       /* kw->parse could set its own io_handler or io_release handler */
+       if (!appctx->io_handler)
+               goto fail;
+
+       appctx->st0 = CLI_ST_CALLBACK;
+       return 1;
+fail:
+       appctx->io_handler = NULL;
+       appctx->io_release = NULL;
        return 1;
 }