From e16d32050e0c91466c2466b93c177f38f66698e2 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Tue, 21 Feb 2023 13:17:24 +0100 Subject: [PATCH] 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. --- src/mworker.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/mworker.c b/src/mworker.c index 0d788ca3d..e6c8e51b0 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; -- 2.47.3