]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
login: avoid leak of name returned by uid_to_name()
authorDavid Tardon <dtardon@redhat.com>
Tue, 9 Oct 2018 15:26:19 +0000 (17:26 +0200)
committerDavid Tardon <dtardon@redhat.com>
Fri, 12 Oct 2018 12:51:35 +0000 (14:51 +0200)
src/login/logind-dbus.c
src/login/logind-utmp.c

index 8e22538ac31e88a07da875aa573e5d575dcd52bb..ed6da4445bae10913c5eac90a17f1b7d41c2c357 100644 (file)
@@ -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);
index 71ebdfcfb170f83c8db1a66176f472a318dce472..8bdd4ab6bf10330edae6e791457e47443e01328e 100644 (file)
@@ -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;
 }