From 5dfb6c4cc9468001938106f5eabbd57e138ecea8 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 16 Oct 2018 19:26:12 +0200 Subject: [PATCH] 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. --- src/server.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/server.c b/src/server.c index 9a03920..c0122b6 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] != '/') { -- 1.7.10.4