diff options
author | Maria Matejka <mq@ucw.cz> | 2021-12-01 10:46:49 +0100 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2021-12-01 13:00:54 +0100 |
commit | 55ee9961e0d130bb16b22b7b5acffd815f266d63 (patch) | |
tree | 2b5f9c0a572871bbe5cbc8ff3f07bd13915b104c /sysdep/unix | |
parent | bb63e99d7877023667edaf26495dd657ec2fd57b (diff) |
Fix of shutdown: premature log cleanup led to use-after-free
Diffstat (limited to 'sysdep/unix')
-rw-r--r-- | sysdep/unix/log.c | 20 | ||||
-rw-r--r-- | sysdep/unix/main.c | 5 | ||||
-rw-r--r-- | sysdep/unix/unix.h | 1 |
3 files changed, 21 insertions, 5 deletions
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c index f48588b6..68a04e78 100644 --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@ -388,6 +388,21 @@ default_log_list(int initial, const char **syslog_name) } void +log_cleanup(int syslog) +{ + struct log_config *l; + + if (current_log_list) + WALK_LIST(l, *current_log_list) + if (l->rf) + log_close(l); + + if (syslog && current_syslog_name) + closelog(); +} + + +void log_switch(int initial, list *logs, const char *new_syslog_name) { struct log_config *l; @@ -399,10 +414,7 @@ log_switch(int initial, list *logs, const char *new_syslog_name) logs = default_log_list(initial, &new_syslog_name); /* Close the logs to avoid pinning them on disk when deleted */ - if (current_log_list) - WALK_LIST(l, *current_log_list) - if (l->rf) - log_close(l); + log_cleanup(0); /* Reopen the logs, needed for 'configure undo' */ if (logs) diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 57c51c99..c326ba2b 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -202,7 +202,9 @@ sysdep_preconfig(struct config *c) int sysdep_commit(struct config *new, struct config *old UNUSED) { - log_switch(0, &new->logfiles, new->syslog_name); + if (!new->shutdown) + log_switch(0, &new->logfiles, new->syslog_name); + return 0; } @@ -613,6 +615,7 @@ sysdep_shutdown_done(void) unlink_pid_file(); unlink(path_control_socket); log_msg(L_FATAL "Shutdown completed"); + log_cleanup(1); exit(0); } diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h index ad85d1ea..51ec1b1e 100644 --- a/sysdep/unix/unix.h +++ b/sysdep/unix/unix.h @@ -122,6 +122,7 @@ void krt_io_init(void); void main_thread_init(void); void log_init_debug(char *); /* Initialize debug dump to given file (NULL=stderr, ""=off) */ void log_switch(int initial, list *l, const char *); +void log_cleanup(int syslog); struct log_config { node n; |