1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 17:51:22 +03:00

Merge pull request #12846 from poettering/cap-last-cap-fix

cap_last_cap() off by one fixes
This commit is contained in:
Yu Watanabe 2019-06-21 03:31:49 +09:00 committed by GitHub
commit a5a4dfa1bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -62,7 +62,7 @@ int capability_set_to_string_alloc(uint64_t set, char **s) {
assert(s);
for (i = 0; i < cap_last_cap(); i++)
for (i = 0; i <= cap_last_cap(); i++)
if (set & (UINT64_C(1) << i)) {
const char *p;
size_t add;

View File

@ -90,7 +90,7 @@ int capability_update_inherited_set(cap_t caps, uint64_t set) {
/* Add capabilities in the set to the inherited caps. Do not apply
* them yet. */
for (i = 0; i < cap_last_cap(); i++) {
for (i = 0; i <= cap_last_cap(); i++) {
if (set & (UINT64_C(1) << i)) {
cap_value_t v;
@ -126,7 +126,7 @@ int capability_ambient_set_apply(uint64_t set, bool also_inherit) {
return -errno;
}
for (i = 0; i < cap_last_cap(); i++) {
for (i = 0; i <= cap_last_cap(); i++) {
if (set & (UINT64_C(1) << i)) {

View File

@ -662,7 +662,9 @@ static int has_cap(sd_bus_creds *c, size_t offset, int capability) {
if ((unsigned long) capability > lc)
return 0;
sz = DIV_ROUND_UP(lc, 32LU);
/* If the last cap is 63, then there are 64 caps defined, and we need 2 entries á 32bit hence. *
* If the last cap is 64, then there are 65 caps defined, and we need 3 entries á 32bit hence. */
sz = DIV_ROUND_UP(lc+1, 32LU);
return !!(c->capability[offset * sz + CAP_TO_INDEX((uint32_t) capability)] & CAP_TO_MASK_CORRECTED((uint32_t) capability));
}
@ -714,7 +716,7 @@ static int parse_caps(sd_bus_creds *c, unsigned offset, const char *p) {
assert(c);
assert(p);
max = DIV_ROUND_UP(cap_last_cap(), 32U);
max = DIV_ROUND_UP(cap_last_cap()+1, 32U);
p += strspn(p, WHITESPACE);
sz = strlen(p);
@ -1259,7 +1261,7 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret)
if (c->mask & mask & (SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS)) {
assert(c->capability);
n->capability = memdup(c->capability, DIV_ROUND_UP(cap_last_cap(), 32U) * 4 * 4);
n->capability = memdup(c->capability, DIV_ROUND_UP(cap_last_cap()+1, 32U) * 4 * 4);
if (!n->capability)
return -ENOMEM;