summaryrefslogtreecommitdiff
path: root/src/shared/capability.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-02-01 15:26:46 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-02-01 17:22:32 -0500
commit7d328b544621d4b1bec936dec612947ad8bfb65a (patch)
tree7d772078fb7a51c9a5561eb9ca7f37eb7e68dcb6 /src/shared/capability.c
parent51ddf61540976fc7b09ce5ace707b27f3acc3871 (diff)
shared/capability: go frugal on space for caps
Diffstat (limited to 'src/shared/capability.c')
-rw-r--r--src/shared/capability.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/shared/capability.c b/src/shared/capability.c
index dcf7ce1a69..3f2f27e23f 100644
--- a/src/shared/capability.c
+++ b/src/shared/capability.c
@@ -269,11 +269,12 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) {
return log_oom();
if (keep_capabilities) {
- cap_value_t bits[sizeof(keep_capabilities)*8];
+ cap_value_t bits[log2u64(keep_capabilities)];
- for (i = 0; i < sizeof(keep_capabilities)*8; i++)
+ for (i = 0; i < ELEMENTSOF(bits); i++)
if (keep_capabilities & (1ULL << i))
bits[j++] = i;
+ assert((keep_capabilities & (~1ULL << i)) == 0);
if (cap_set_flag(d, CAP_EFFECTIVE, j, bits, CAP_SET) < 0 ||
cap_set_flag(d, CAP_PERMITTED, j, bits, CAP_SET) < 0) {