From fc2dd0939002b1edf7ced4b653c9d6640576a213 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 26 Oct 2023 12:21:57 +0000 Subject: [PATCH 1/3] Fix assertion failure when using -X none and lock-file in configuration When 'lock-file ' is used in configuration at the same time as using '-X none' in 'named' invocation, there is an invalid logic that would lead to a isc_mem_strdup() call on a NULL value. Also, contradicting to ARM, 'lock-file none' is overriding the '-X' argument. Fix the overall logic, and make sure that the '-X' takes precedence to 'lock-file'. --- bin/named/server.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/bin/named/server.c b/bin/named/server.c index e2d49b7341..61d782d9dd 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -8166,27 +8166,24 @@ check_lockfile(named_server_t *server, const cfg_obj_t *config, } if (obj != NULL) { - if (cfg_obj_isvoid(obj)) { - isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, - NAMED_LOGMODULE_SERVER, ISC_LOG_DEBUG(1), - "skipping lock-file check "); - return (ISC_R_SUCCESS); - } else if (named_g_forcelock) { + if (named_g_forcelock) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING, "'lock-file' has no effect " "because the server was run with -X"); - server->lockfile = isc_mem_strdup( - server->mctx, named_g_defaultlockfile); - } else { + if (named_g_defaultlockfile != NULL) { + server->lockfile = isc_mem_strdup( + server->mctx, named_g_defaultlockfile); + } + } else if (cfg_obj_isvoid(obj)) { + isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, + NAMED_LOGMODULE_SERVER, ISC_LOG_DEBUG(1), + "skipping lock-file check"); + } else if (cfg_obj_isstring(obj)) { filename = cfg_obj_asstring(obj); server->lockfile = isc_mem_strdup(server->mctx, filename); } - - if (server->lockfile == NULL) { - return (ISC_R_NOMEMORY); - } } else if (named_g_forcelock && named_g_defaultlockfile != NULL) { server->lockfile = isc_mem_strdup(server->mctx, named_g_defaultlockfile); From bc891e749fe361caeb7d7ca5208ebf1e1f4f02ac Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 26 Oct 2023 12:24:17 +0000 Subject: [PATCH 2/3] Fix an invalid condition check when detecting a lock-file change It is obvious that the '!cfg_obj_asstring(obj)' check should be 'cfg_obj_asstring(obj)' instead, because it is an AND logic chain which further uses 'obj' as a string. Fix the error. --- bin/named/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/named/server.c b/bin/named/server.c index 61d782d9dd..a6b2c2be9b 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -8151,7 +8151,7 @@ check_lockfile(named_server_t *server, const cfg_obj_t *config, (void)named_config_get(maps, "lock-file", &obj); if (!first_time) { - if (obj != NULL && !cfg_obj_isstring(obj) && + if (obj != NULL && cfg_obj_isstring(obj) && server->lockfile != NULL && strcmp(cfg_obj_asstring(obj), server->lockfile) != 0) { From 41945b32d76c99e18c697d03ebc039091386667c Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 26 Oct 2023 12:28:25 +0000 Subject: [PATCH 3/3] Do not warn about lock-file option change when -X is used When -X is used the 'lock-file' option change detection condition is invalid, because it compares the 'lock-file' option's value to the '-X' argument's value instead of the older 'lock-file' option value (which was ignored because of '-X'). Don't warn about changing 'lock-file' option if '-X' is used. --- bin/named/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/named/server.c b/bin/named/server.c index a6b2c2be9b..15bcfa7ffa 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -8152,7 +8152,7 @@ check_lockfile(named_server_t *server, const cfg_obj_t *config, if (!first_time) { if (obj != NULL && cfg_obj_isstring(obj) && - server->lockfile != NULL && + server->lockfile != NULL && !named_g_forcelock && strcmp(cfg_obj_asstring(obj), server->lockfile) != 0) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,