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