From: Willy Tarreau Date: Fri, 12 Mar 2021 12:57:19 +0000 (+0100) Subject: BUG/MINOR: server-state: properly handle the case where the base is not set X-Git-Tag: v2.4-dev12~48 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=6d4173e62291ae81ad4882a70871eefd46630b38;p=haproxy-2.5.git BUG/MINOR: server-state: properly handle the case where the base is not set The refactoring in commit 131b07be3 ("MEDIUM: server: Refactor apply_server_state() to make it more readable") made the global server_state_base be dereferenced before being checked, resulting in a crash on certain files. This happened in 2.4-dev10, no backport is needed. --- diff --git a/src/server_state.c b/src/server_state.c index 468cfd3..93971e7 100644 --- a/src/server_state.c +++ b/src/server_state.c @@ -727,7 +727,7 @@ static int srv_state_parse_and_store_line(char *line, int vsn, struct eb_root *s */ static inline int srv_state_get_filepath(char *dst_path, int maxpathlen, const char *filename) { - char *sep = (global.server_state_base[strlen(global.server_state_base)-1] != '/' ? "/": ""); + char *sep; int len = 0; /* create the globalfilepath variable */ @@ -739,6 +739,7 @@ static inline int srv_state_get_filepath(char *dst_path, int maxpathlen, const c } else { /* concat base directory and global server-state file */ + sep = (global.server_state_base[strlen(global.server_state_base)-1] != '/' ? "/": ""); len = snprintf(dst_path, maxpathlen, "%s%s%s", global.server_state_base, sep, filename); } return (len < maxpathlen ? len: -1);