From 487657b2b82da6516f6b96f7dacc92db9f28ede6 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 12 Jun 2012 16:45:20 -0700 Subject: [PATCH] vlog: Avoid use-after-free in corner case. Found by valgrind. Signed-off-by: Ben Pfaff --- lib/vlog.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/vlog.c b/lib/vlog.c index a7d9e48b..899072e4 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -477,6 +477,7 @@ vlog_unixctl_reopen(struct unixctl_conn *conn, int argc OVS_UNUSED, void vlog_init(void) { + static char *program_name_copy; time_t now; if (vlog_inited) { @@ -484,7 +485,13 @@ vlog_init(void) } vlog_inited = true; - openlog(program_name, LOG_NDELAY, LOG_DAEMON); + /* openlog() is allowed to keep the pointer passed in, without making a + * copy. The daemonize code sometimes frees and replaces 'program_name', + * so make a private copy just for openlog(). (We keep a pointer to the + * private copy to suppress memory leak warnings in case openlog() does + * make its own copy.) */ + program_name_copy = program_name ? xstrdup(program_name) : NULL; + openlog(program_name_copy, LOG_NDELAY, LOG_DAEMON); now = time_wall(); if (now < 0) { -- 2.30.2