]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cli: Guard against NULL messages when using CLI_ST_PRINT_FREE
authorAurélien Nephtali <aurelien.nephtali@corp.ovh.com>
Mon, 16 Apr 2018 16:50:19 +0000 (18:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 16 Apr 2018 17:22:42 +0000 (19:22 +0200)
Some error paths (especially those followed when running out of memory)
can set the error message to NULL. In order to avoid a crash, use a
generic message ("Out of memory") when this case arises.

It should be backported to 1.8.

Signed-off-by: Aurélien Nephtali <aurelien.nephtali@corp.ovh.com>
src/cli.c

index 018d508d321f6c3ad60f7f0f43ace927f19f2f6f..965709ec83d6405b486beee01c70f5e3159e08f1 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -625,14 +625,20 @@ static void cli_io_handler(struct appctx *appctx)
                                else
                                        si_applet_cant_put(si);
                                break;
-                       case CLI_ST_PRINT_FREE:
-                               if (cli_output_msg(res, appctx->ctx.cli.err, LOG_ERR, cli_get_severity_output(appctx)) != -1) {
+                       case CLI_ST_PRINT_FREE: {
+                               const char *msg = appctx->ctx.cli.err;
+
+                               if (!msg)
+                                       msg = "Out of memory.\n";
+
+                               if (cli_output_msg(res, msg, LOG_ERR, cli_get_severity_output(appctx)) != -1) {
                                        free(appctx->ctx.cli.err);
                                        appctx->st0 = CLI_ST_PROMPT;
                                }
                                else
                                        si_applet_cant_put(si);
                                break;
+                       }
                        case CLI_ST_CALLBACK: /* use custom pointer */
                                if (appctx->io_handler)
                                        if (appctx->io_handler(appctx)) {