From: David Tardon Date: Tue, 9 Oct 2018 15:26:19 +0000 (+0200) Subject: login: avoid leak of name returned by uid_to_name() X-Git-Tag: v240~563^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e99742ef3e9d847da04e71fec0eb426063b25068;p=thirdparty%2Fsystemd.git login: avoid leak of name returned by uid_to_name() --- diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 8e22538ac31..ed6da4445ba 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2157,6 +2157,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd if (cancelled && m->enable_wall_messages) { _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; + _cleanup_free_ char *username = NULL; const char *tty = NULL; uid_t uid = 0; int r; @@ -2167,8 +2168,9 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd (void) sd_bus_creds_get_tty(creds, &tty); } + username = uid_to_name(uid); utmp_wall("The system shutdown has been cancelled", - uid_to_name(uid), tty, logind_wall_tty_filter, m); + username, tty, logind_wall_tty_filter, m); } return sd_bus_reply_method_return(message, "b", cancelled); diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index 71ebdfcfb17..8bdd4ab6bf1 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -61,7 +61,7 @@ bool logind_wall_tty_filter(const char *tty, void *userdata) { static int warn_wall(Manager *m, usec_t n) { char date[FORMAT_TIMESTAMP_MAX] = {}; - _cleanup_free_ char *l = NULL; + _cleanup_free_ char *l = NULL, *username = NULL; usec_t left; int r; @@ -83,8 +83,8 @@ static int warn_wall(Manager *m, usec_t n) { return 0; } - utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid), - m->scheduled_shutdown_tty, logind_wall_tty_filter, m); + username = uid_to_name(m->scheduled_shutdown_uid); + utmp_wall(l, username, m->scheduled_shutdown_tty, logind_wall_tty_filter, m); return 1; }