From: William Lallemand Date: Tue, 21 Feb 2023 12:17:24 +0000 (+0100) Subject: BUG/MEDIUM: mworker: prevent inconsistent reload when upgrading from old versions X-Git-Tag: v2.8-dev5~145 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e16d32050e0c91466c2466b93c177f38f66698e2;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: mworker: prevent inconsistent reload when upgrading from old versions 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. --- diff --git a/src/mworker.c b/src/mworker.c index 0d788ca3d1..e6c8e51b0d 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -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;