]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
capability-util: tighten requirement for CAP_LAST_CAP off by one
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Oct 2025 16:52:02 +0000 (01:52 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Oct 2025 16:52:18 +0000 (01:52 +0900)
Otherwise, we cannot use UINT64_MAX as 'unset'.

src/basic/capability-util.h
src/test/test-capability-util.c

index 09b612b1e666f122daa19ea0617e49eb423fbe41..fa8b591759ca03cd35fdc54d4a29887ec56d07b9 100644 (file)
@@ -8,7 +8,6 @@
 /* Special marker used when storing a capabilities mask as "unset". This would need to be updated as soon as
  * Linux learns more than 63 caps. */
 #define CAP_MASK_UNSET UINT64_MAX
-assert_cc(CAP_LAST_CAP < 64);
 
 /* All possible capabilities bits on */
 #define CAP_MASK_ALL UINT64_C(0x7fffffffffffffff)
@@ -16,6 +15,7 @@ assert_cc(CAP_LAST_CAP < 64);
 /* The largest capability we can deal with, given we want to be able to store cap masks in uint64_t but still
  * be able to use UINT64_MAX as indicator for "not set". The latter makes capability 63 unavailable. */
 #define CAP_LIMIT 62
+assert_cc(CAP_LAST_CAP <= CAP_LIMIT);
 
 static inline bool capability_is_set(uint64_t v) {
         return v != CAP_MASK_UNSET;
index 881aafbc7f441f91628abcbbe3b91a629c410e3f..67a61c7eaf020024a164c423729602818fdcb6a1 100644 (file)
@@ -241,11 +241,9 @@ static void test_ensure_cap_64_bit(void) {
 
         ASSERT_OK(safe_atolu(content, &p));
 
-        /* If caps don't fit into 64-bit anymore, we have a problem, fail the test. */
-        assert_se(p <= 63);
-
-        /* Also check for the header definition */
-        assert_cc(CAP_LAST_CAP <= 63);
+        /* If caps don't fit into 64-bit anymore, we have a problem, fail the test. Moreover, we use
+         * UINT64_MAX as unset, hence it must be smaller than or equals to 62 (CAP_LIMIT). */
+        assert_se(p <= CAP_LIMIT);
 }
 
 static void test_capability_get_ambient(void) {