0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-10 13:18:42 +00:00

Fix of shutdown: premature log cleanup led to use-after-free

This commit is contained in:
Maria Matejka 2021-12-01 10:46:49 +01:00
parent bb63e99d78
commit 55ee9961e0
3 changed files with 21 additions and 5 deletions

View File

@ -387,6 +387,21 @@ default_log_list(int initial, const char **syslog_name)
return &log_list; return &log_list;
} }
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 void
log_switch(int initial, list *logs, const char *new_syslog_name) log_switch(int initial, list *logs, const char *new_syslog_name)
{ {
@ -399,10 +414,7 @@ log_switch(int initial, list *logs, const char *new_syslog_name)
logs = default_log_list(initial, &new_syslog_name); logs = default_log_list(initial, &new_syslog_name);
/* Close the logs to avoid pinning them on disk when deleted */ /* Close the logs to avoid pinning them on disk when deleted */
if (current_log_list) log_cleanup(0);
WALK_LIST(l, *current_log_list)
if (l->rf)
log_close(l);
/* Reopen the logs, needed for 'configure undo' */ /* Reopen the logs, needed for 'configure undo' */
if (logs) if (logs)

View File

@ -202,7 +202,9 @@ sysdep_preconfig(struct config *c)
int int
sysdep_commit(struct config *new, struct config *old UNUSED) sysdep_commit(struct config *new, struct config *old UNUSED)
{ {
if (!new->shutdown)
log_switch(0, &new->logfiles, new->syslog_name); log_switch(0, &new->logfiles, new->syslog_name);
return 0; return 0;
} }
@ -613,6 +615,7 @@ sysdep_shutdown_done(void)
unlink_pid_file(); unlink_pid_file();
unlink(path_control_socket); unlink(path_control_socket);
log_msg(L_FATAL "Shutdown completed"); log_msg(L_FATAL "Shutdown completed");
log_cleanup(1);
exit(0); exit(0);
} }

View File

@ -122,6 +122,7 @@ void krt_io_init(void);
void main_thread_init(void); void main_thread_init(void);
void log_init_debug(char *); /* Initialize debug dump to given file (NULL=stderr, ""=off) */ 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_switch(int initial, list *l, const char *);
void log_cleanup(int syslog);
struct log_config { struct log_config {
node n; node n;