From: Timo Sirainen Date: Tue, 15 Jul 2025 09:32:23 +0000 (+0300) Subject: lib: Fix crash when config is reloaded and logging to syslog X-Git-Tag: 2.4.2~663 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9240e3a4386808789d593537a8ebe3e873e89683;p=thirdparty%2Fdovecot%2Fcore.git lib: Fix crash when config is reloaded and logging to syslog openlog() was called with a string pointing to settings. When settings were reloaded, the pointer became invalid, causing syslog() to crash. --- diff --git a/src/lib/failures.c b/src/lib/failures.c index eae2d8ddf8..49b0681607 100644 --- a/src/lib/failures.c +++ b/src/lib/failures.c @@ -56,6 +56,7 @@ static struct failure_context failure_ctx_error = { .type = LOG_TYPE_ERROR }; static int log_fd = STDERR_FILENO, log_info_fd = STDERR_FILENO, log_debug_fd = STDERR_FILENO; +static char *syslog_ident = NULL; static char *log_prefix = NULL; static char *log_stamp_format = NULL, *log_stamp_format_suffix = NULL; static bool failure_ignore_errors = FALSE, log_prefix_sent = FALSE; @@ -657,7 +658,11 @@ void i_syslog_error_handler(const struct failure_context *ctx, void i_set_failure_syslog(const char *ident, int options, int facility) { - openlog(ident, options, facility); + /* openlog() keeps using the pointer directly. Duplicate it in case + caller frees the string. */ + i_free(syslog_ident); + syslog_ident = i_strdup(ident); + openlog(syslog_ident, options, facility); i_set_fatal_handler(i_syslog_fatal_handler); i_set_error_handler(i_syslog_error_handler); @@ -1006,6 +1011,7 @@ void failures_deinit(void) i_free_and_null(log_prefix); i_free_and_null(log_stamp_format); i_free_and_null(log_stamp_format_suffix); + i_free(syslog_ident); } #undef i_unreached