From: Willy Tarreau Date: Fri, 12 Mar 2021 13:09:10 +0000 (+0100) Subject: BUG/MINOR: server-state: use the argument, not the global state X-Git-Tag: v2.4-dev12~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47a30c456c8ba8c77a501aa43cd4a1ce79f6941b;p=thirdparty%2Fhaproxy.git BUG/MINOR: server-state: use the argument, not the global state The refactoring in commit 131b07be3 ("MEDIUM: server: Refactor apply_server_state() to make it more readable") also had a copy-paste error resulting in using global.server_state_file instead of the function's argument, which easily crashes with a conf having a state file in a backend and no global state file. In addition, let's simplify the code and get rid of strcpy() which almost certainly will break the build on OpenBSD. This was introduced in 2.4-dev10, no backport is needed. --- diff --git a/src/server_state.c b/src/server_state.c index 93971e7048..72353059c4 100644 --- a/src/server_state.c +++ b/src/server_state.c @@ -733,9 +733,7 @@ static inline int srv_state_get_filepath(char *dst_path, int maxpathlen, const c /* create the globalfilepath variable */ if (*filename == '/' || !global.server_state_base) { /* absolute path or no base directory provided */ - len = strlen(filename); - if (len < maxpathlen) - strcpy(dst_path, global.server_state_file); + len = strlcpy2(dst_path, filename, maxpathlen); } else { /* concat base directory and global server-state file */