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/log.c | |
parent | bb63e99d7877023667edaf26495dd657ec2fd57b (diff) |
Fix of shutdown: premature log cleanup led to use-after-free
Diffstat (limited to 'sysdep/unix/log.c')
-rw-r--r-- | sysdep/unix/log.c | 20 |
1 files changed, 16 insertions, 4 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) |