]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: Ensure the CLI always outputs an error when it should
authorAurélien Nephtali <aurelien.nephtali@corp.ovh.com>
Mon, 16 Apr 2018 17:02:42 +0000 (19:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 16 Apr 2018 17:23:16 +0000 (19:23 +0200)
When using the CLI_ST_PRINT_FREE state, always output something back
if the faulty function did not fill the 'err' variable.
The map/acl code could lead to a crash whereas the SSL code was silently
failing.

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

index 9313dc87e4b6dc299319afc68babff5abdc810fa..7953c2a0be3fe58fa02bf3c9f5a6e5cd83fcf49b 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -723,15 +723,21 @@ static int cli_parse_set_map(char **args, struct appctx *appctx, void *private)
                                return 1;
                        }
 
-                       /* Try to delete the entry. */
+                       /* Try to modify the entry. */
                        err = NULL;
                        HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
                        if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) {
                                HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
-                               if (err)
+                               if (err) {
                                        memprintf(&err, "%s.\n", err);
-                               appctx->ctx.cli.err = err;
-                               appctx->st0 = CLI_ST_PRINT_FREE;
+                                       appctx->ctx.cli.err = err;
+                                       appctx->st0 = CLI_ST_PRINT_FREE;
+                               }
+                               else {
+                                       appctx->ctx.cli.severity = LOG_ERR;
+                                       appctx->ctx.cli.msg = "Failed to update an entry.\n";
+                                       appctx->st0 = CLI_ST_PRINT;
+                               }
                                return 1;
                        }
                        HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
@@ -744,10 +750,16 @@ static int cli_parse_set_map(char **args, struct appctx *appctx, void *private)
                        HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
                        if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) {
                                HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
-                               if (err)
+                               if (err) {
                                        memprintf(&err, "%s.\n", err);
-                               appctx->ctx.cli.err = err;
-                               appctx->st0 = CLI_ST_PRINT_FREE;
+                                       appctx->ctx.cli.err = err;
+                                       appctx->st0 = CLI_ST_PRINT_FREE;
+                               }
+                               else {
+                                       appctx->ctx.cli.severity = LOG_ERR;
+                                       appctx->ctx.cli.msg = "Failed to update an entry.\n";
+                                       appctx->st0 = CLI_ST_PRINT;
+                               }
                                return 1;
                        }
                        HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
@@ -829,10 +841,16 @@ static int cli_parse_add_map(char **args, struct appctx *appctx, void *private)
                        ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err);
                HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
                if (!ret) {
-                       if (err)
+                       if (err) {
                                memprintf(&err, "%s.\n", err);
-                       appctx->ctx.cli.err = err;
-                       appctx->st0 = CLI_ST_PRINT_FREE;
+                               appctx->ctx.cli.err = err;
+                               appctx->st0 = CLI_ST_PRINT_FREE;
+                       }
+                       else {
+                               appctx->ctx.cli.severity = LOG_ERR;
+                               appctx->ctx.cli.msg = "Failed to add an entry.\n";
+                               appctx->st0 = CLI_ST_PRINT;
+                       }
                        return 1;
                }
 
index 8151cb381064e59154023ab870ff7cc60e28afa2..23ad35b187cda3779d3b386f2548402119636c22 100644 (file)
@@ -8588,6 +8588,11 @@ static int cli_parse_set_ocspresponse(char **args, struct appctx *appctx, void *
                        appctx->ctx.cli.err = err;
                        appctx->st0 = CLI_ST_PRINT_FREE;
                }
+               else {
+                       appctx->ctx.cli.severity = LOG_ERR;
+                       appctx->ctx.cli.msg = "Failed to update OCSP response.\n";
+                       appctx->st0 = CLI_ST_PRINT;
+               }
                return 1;
        }
        appctx->ctx.cli.severity = LOG_INFO;