ff6046
From 8fdca31b41a6470ceda8e0a84f90a1e5ca28aa5c Mon Sep 17 00:00:00 2001
ff6046
From: David Tardon <dtardon@redhat.com>
ff6046
Date: Tue, 9 Oct 2018 17:26:19 +0200
ff6046
Subject: [PATCH] login: avoid leak of name returned by uid_to_name()
ff6046
ff6046
(cherry picked from commit e99742ef3e9d847da04e71fec0eb426063b25068)
ff6046
ff6046
Resolves: #1602706
ff6046
---
ff6046
 src/login/logind-dbus.c | 4 +++-
ff6046
 src/login/logind-utmp.c | 6 +++---
ff6046
 2 files changed, 6 insertions(+), 4 deletions(-)
ff6046
ff6046
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
ff6046
index 13298cc855..dca7f4a30f 100644
ff6046
--- a/src/login/logind-dbus.c
ff6046
+++ b/src/login/logind-dbus.c
ff6046
@@ -2155,6 +2155,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
ff6046
 
ff6046
         if (cancelled && m->enable_wall_messages) {
ff6046
                 _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
ff6046
+                _cleanup_free_ char *username = NULL;
ff6046
                 const char *tty = NULL;
ff6046
                 uid_t uid = 0;
ff6046
                 int r;
ff6046
@@ -2165,8 +2166,9 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
ff6046
                         (void) sd_bus_creds_get_tty(creds, &tty);
ff6046
                 }
ff6046
 
ff6046
+                username = uid_to_name(uid);
ff6046
                 utmp_wall("The system shutdown has been cancelled",
ff6046
-                          uid_to_name(uid), tty, logind_wall_tty_filter, m);
ff6046
+                          username, tty, logind_wall_tty_filter, m);
ff6046
         }
ff6046
 
ff6046
         return sd_bus_reply_method_return(message, "b", cancelled);
ff6046
diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c
ff6046
index 71ebdfcfb1..8bdd4ab6bf 100644
ff6046
--- a/src/login/logind-utmp.c
ff6046
+++ b/src/login/logind-utmp.c
ff6046
@@ -61,7 +61,7 @@ bool logind_wall_tty_filter(const char *tty, void *userdata) {
ff6046
 
ff6046
 static int warn_wall(Manager *m, usec_t n) {
ff6046
         char date[FORMAT_TIMESTAMP_MAX] = {};
ff6046
-        _cleanup_free_ char *l = NULL;
ff6046
+        _cleanup_free_ char *l = NULL, *username = NULL;
ff6046
         usec_t left;
ff6046
         int r;
ff6046
 
ff6046
@@ -83,8 +83,8 @@ static int warn_wall(Manager *m, usec_t n) {
ff6046
                 return 0;
ff6046
         }
ff6046
 
ff6046
-        utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid),
ff6046
-                  m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
ff6046
+        username = uid_to_name(m->scheduled_shutdown_uid);
ff6046
+        utmp_wall(l, username, m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
ff6046
 
ff6046
         return 1;
ff6046
 }