teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0186-sd-bus-call-cap_last_cap-only-once-in-has_cap.patch

ff6046
From 770b16b22dd0eec04fd1493dae644206c32f8e04 Mon Sep 17 00:00:00 2001
ff6046
From: Lennart Poettering <lennart@poettering.net>
ff6046
Date: Wed, 10 Oct 2018 11:12:54 +0200
ff6046
Subject: [PATCH] sd-bus: call cap_last_cap() only once in has_cap()
ff6046
ff6046
Also, use the same type everywhere for dealing with it.
ff6046
ff6046
(cherry picked from commit 92a40e20bf970c3ded8a50fbeeae882a7b970c9a)
ff6046
ff6046
Resolves: #1683319
ff6046
---
ff6046
 src/libsystemd/sd-bus/bus-creds.c | 7 +++++--
ff6046
 1 file changed, 5 insertions(+), 2 deletions(-)
ff6046
ff6046
diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c
ff6046
index 6896bcf246..2a47c68ffc 100644
ff6046
--- a/src/libsystemd/sd-bus/bus-creds.c
ff6046
+++ b/src/libsystemd/sd-bus/bus-creds.c
ff6046
@@ -652,16 +652,19 @@ _public_ int sd_bus_creds_get_description(sd_bus_creds *c, const char **ret) {
ff6046
 }
ff6046
 
ff6046
 static int has_cap(sd_bus_creds *c, size_t offset, int capability) {
ff6046
+        unsigned long lc;
ff6046
         size_t sz;
ff6046
 
ff6046
         assert(c);
ff6046
         assert(capability >= 0);
ff6046
         assert(c->capability);
ff6046
 
ff6046
-        if ((unsigned) capability > cap_last_cap())
ff6046
+        lc = cap_last_cap();
ff6046
+
ff6046
+        if ((unsigned long) capability > lc)
ff6046
                 return 0;
ff6046
 
ff6046
-        sz = DIV_ROUND_UP(cap_last_cap(), 32U);
ff6046
+        sz = DIV_ROUND_UP(lc, 32LU);
ff6046
 
ff6046
         return !!(c->capability[offset * sz + CAP_TO_INDEX((uint32_t) capability)] & CAP_TO_MASK_CORRECTED((uint32_t) capability));
ff6046
 }