]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mworker: prevent inconsistent reload when upgrading from old versions
authorWilliam Lallemand <wlallemand@haproxy.org>
Tue, 21 Feb 2023 12:17:24 +0000 (13:17 +0100)
committerWilliam Lallemand <wlallemand@haproxy.org>
Tue, 21 Feb 2023 12:53:35 +0000 (13:53 +0100)
Previous versions ( < 1.9 ) of the master-worker process didn't had the
"HAPROXY_PROCESSES" environment variable which contains the list of
processes, fd etc.

The part which describes the master is created at first startup so if
you started the master with an old version you would never have
it.

Since patch 68836740 ("MINOR: mworker: implement a reload failure
counter"), the failedreloads member of the proc_self structure for the
master is set to 0. However if this structure does not exist, it will
result in a NULL dereference and crash the master.

This patch fixes the issue by creating the proc_self structure for the
master when it does not exist. It also shows a warning which states to
restart the master if that is the case, because we can't guarantee that
it will be working correctly.

This MUST be backported as far as 2.5, and could be backported in every
other stable branches.

src/mworker.c

index 0d788ca3d1072dc08832eebea576a1bc1b872b60..e6c8e51b0d83b85ccd469ee955bc667a4ad8b67f 100644 (file)
@@ -177,7 +177,7 @@ int mworker_env_to_proc_list()
 
        env = getenv("HAPROXY_PROCESSES");
        if (!env)
-               return 0;
+               goto no_env;
 
        omsg = msg = strdup(env);
        if (!msg) {
@@ -254,6 +254,24 @@ int mworker_env_to_proc_list()
 
        unsetenv("HAPROXY_PROCESSES");
 
+no_env:
+
+       if (!proc_self) {
+
+               proc_self = mworker_proc_new();
+               if (!proc_self) {
+                       ha_alert("Cannot allocate process structures.\n");
+                       err = -1;
+                       goto out;
+               }
+               proc_self->options |= PROC_O_TYPE_MASTER;
+               proc_self->pid = pid;
+               proc_self->timestamp = 0; /* we don't know the startime anymore */
+
+               LIST_APPEND(&proc_list, &proc_self->list);
+               ha_warning("The master internals are corrupted or it was started with a too old version (< 1.9). Please restart the master process.\n");
+       }
+
 out:
        free(omsg);
        return err;