From: Willy Tarreau Date: Tue, 16 Oct 2018 17:26:12 +0000 (+0200) Subject: CLEANUP: state-file: make the path concatenation code a bit more consistent X-Git-Tag: v1.9-dev4~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5dfb6c4cc9468001938106f5eabbd57e138ecea8;p=thirdparty%2Fhaproxy.git CLEANUP: state-file: make the path concatenation code a bit more consistent There are as many ways to build the globalfilepathlen variable as branches in the if/then/else, creating lots of confusion. Address the most obvious parts, but some polishing definitely is still needed. --- diff --git a/src/server.c b/src/server.c index 9a0392084f..c0122b6689 100644 --- a/src/server.c +++ b/src/server.c @@ -3164,14 +3164,13 @@ void apply_server_state(void) } else if (global.server_state_base) { len = strlen(global.server_state_base); - globalfilepathlen += len; - - if (globalfilepathlen > MAXPATHLEN) { + if (len > MAXPATHLEN) { globalfilepathlen = 0; goto globalfileerror; } memcpy(globalfilepath, global.server_state_base, len); - globalfilepath[globalfilepathlen] = 0; + globalfilepath[len] = 0; + globalfilepathlen = len; /* append a slash if needed */ if (!globalfilepathlen || globalfilepath[globalfilepathlen - 1] != '/') {