daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
803fb7
From 3b573e5c39f452f98084b3d36486369882455b72 Mon Sep 17 00:00:00 2001
803fb7
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
803fb7
Date: Sat, 7 Feb 2015 11:16:04 -0500
803fb7
Subject: [PATCH] systemctl: check validity of PID we received
803fb7
803fb7
(cherry picked from commit d028e01814a405e83c400c60545785d35dba2a17)
803fb7
---
803fb7
 src/systemctl/systemctl.c | 5 ++++-
803fb7
 1 file changed, 4 insertions(+), 1 deletion(-)
803fb7
803fb7
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
803fb7
index 6b93ec844..3da4d3d4f 100644
803fb7
--- a/src/systemctl/systemctl.c
803fb7
+++ b/src/systemctl/systemctl.c
803fb7
@@ -2881,6 +2881,9 @@ static int check_inhibitors(sd_bus *bus, enum action a) {
803fb7
                 if (!sv)
803fb7
                         return log_oom();
803fb7
 
803fb7
+                if ((pid_t) pid < 0)
803fb7
+                        return log_error_errno(ERANGE, "Bad PID %"PRIu32": %m", pid);
803fb7
+
803fb7
                 if (!strv_contains(sv,
803fb7
                                   a == ACTION_HALT ||
803fb7
                                   a == ACTION_POWEROFF ||
803fb7
@@ -2892,7 +2895,7 @@ static int check_inhibitors(sd_bus *bus, enum action a) {
803fb7
                 user = uid_to_name(uid);
803fb7
 
803fb7
                 log_warning("Operation inhibited by \"%s\" (PID "PID_FMT" \"%s\", user %s), reason is \"%s\".",
803fb7
-                            who, pid, strna(comm), strna(user), why);
803fb7
+                            who, (pid_t) pid, strna(comm), strna(user), why);
803fb7
 
803fb7
                 c++;
803fb7
         }