summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-02-04 09:23:24 +0100
committerTom Gundersen <teg@jklm.no>2015-02-04 09:28:42 +0100
commit057255fbbf2ecb1c46e025b04087fa9340d9880d (patch)
treee0235944556422ba347582a522717791d37d6a68
parent798d3a524ea57aaf40cb53858aaa45ec702f012d (diff)
shared/capability: don't be too frugal on space for caps
We were dropping the most significant bit. Add an assert to make sure it does not happen again. Fixes a bug introduced in 7d328b544621d4b1bec936dec612947ad8bfb65a.
-rw-r--r--src/shared/capability.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/shared/capability.c b/src/shared/capability.c
index 3f2f27e23f..57f392a4da 100644
--- a/src/shared/capability.c
+++ b/src/shared/capability.c
@@ -269,12 +269,16 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) {
return log_oom();
if (keep_capabilities) {
- cap_value_t bits[log2u64(keep_capabilities)];
+ cap_value_t bits[u64log2(keep_capabilities) + 1];
for (i = 0; i < ELEMENTSOF(bits); i++)
if (keep_capabilities & (1ULL << i))
bits[j++] = i;
+
+ /* don't keep too many bits */
assert((keep_capabilities & (~1ULL << i)) == 0);
+ /* don't throw away too many bits */
+ assert(((keep_capabilities >> i) & (~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) {