daandemeyer / rpms / systemd

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