]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: log: fix multiple error paths in cfg_parse_log_forward()
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 3 Jul 2023 16:33:18 +0000 (18:33 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 10 Jul 2023 16:28:08 +0000 (18:28 +0200)
Multiple error paths were badly handled in cfg_parse_log_forward():
some errors were raised without interrupting the function execution,
resulting in undefined behavior.

Instead of fixing issues separately, let's fix the whole function at once.
This should be backported as far as 2.4.

src/log.c

index 3e5f97ea21b490ab069a0bf0de231f25f2a5662e..93570b4dd7e167336819a309bb925937463a3792 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -3720,7 +3720,7 @@ static struct applet syslog_applet = {
  */
 int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
 {
-       int err_code = 0;
+       int err_code = ERR_NONE;
        struct proxy *px;
        char *errmsg = NULL;
        const char *err = NULL;
@@ -3748,6 +3748,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                        ha_alert("Parsing [%s:%d]: log-forward section '%s' has the same name as another log-forward section declared at %s:%d.\n",
                                 file, linenum, args[1], px->conf.file, px->conf.line);
                        err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
                }
 
                px = proxy_find_by_name(args[1], 0, 0);
@@ -3756,6 +3757,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                                 file, linenum, args[1], proxy_type_str(px),
                                 px->id, px->conf.file, px->conf.line);
                        err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
                }
 
                px = calloc(1, sizeof *px);
@@ -3777,7 +3779,6 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                px->accept = frontend_accept;
                px->default_target = &syslog_applet.obj_type;
                px->id = strdup(args[1]);
-
        }
        else if (strcmp(args[0], "maxconn") == 0) {  /* maxconn */
                if (warnifnotcap(cfg_log_forward, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
@@ -3832,9 +3833,9 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                        else {
                                ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
                                         file, linenum, args[0], args[1], args[2]);
-                               err_code |= ERR_ALERT | ERR_FATAL;
-                               goto out;
                        }
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
                }
                list_for_each_entry(l, &bind_conf->listeners, by_bind) {
                        global.maxsock++;
@@ -3946,7 +3947,6 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                }
                else if (res) {
                        memprintf(&errmsg, "unexpected character '%c' in 'timeout client'", *res);
-                       return -1;
                }
 
                if (res) {