checkpolicy: Fix potential undefined shifts
An expression of the form "1 << x" is undefined if x == 31 because the "1" is an int and cannot be left shifted by 31. Instead, use "UINT32_C(1) << x" which will be an unsigned int of at least 32 bits. Signed-off-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
parent
974da80e08
commit
ce815bd11b
2 changed files with 5 additions and 5 deletions
|
@ -794,7 +794,7 @@ int main(int argc, char **argv)
|
||||||
case 0:
|
case 0:
|
||||||
printf("\nallowed {");
|
printf("\nallowed {");
|
||||||
for (i = 1; i <= sizeof(avd.allowed) * 8; i++) {
|
for (i = 1; i <= sizeof(avd.allowed) * 8; i++) {
|
||||||
if (avd.allowed & (1 << (i - 1))) {
|
if (avd.allowed & (UINT32_C(1) << (i - 1))) {
|
||||||
v.val = i;
|
v.val = i;
|
||||||
ret =
|
ret =
|
||||||
hashtab_map(cladatum->
|
hashtab_map(cladatum->
|
||||||
|
|
|
@ -2126,7 +2126,7 @@ static int define_te_avtab_xperms_helper(int which, avrule_t ** rule)
|
||||||
policydbp->p_class_val_to_name[i]);
|
policydbp->p_class_val_to_name[i]);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
cur_perms->data |= 1U << (perdatum->s.value - 1);
|
cur_perms->data |= UINT32_C(1) << (perdatum->s.value - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2142,7 +2142,7 @@ out:
|
||||||
/* index of the u32 containing the permission */
|
/* index of the u32 containing the permission */
|
||||||
#define XPERM_IDX(x) ((x) >> 5)
|
#define XPERM_IDX(x) ((x) >> 5)
|
||||||
/* set bits 0 through x-1 within the u32 */
|
/* set bits 0 through x-1 within the u32 */
|
||||||
#define XPERM_SETBITS(x) ((1U << ((x) & 0x1f)) - 1)
|
#define XPERM_SETBITS(x) ((UINT32_C(1) << ((x) & 0x1f)) - 1)
|
||||||
/* low value for this u32 */
|
/* low value for this u32 */
|
||||||
#define XPERM_LOW(x) ((x) << 5)
|
#define XPERM_LOW(x) ((x) << 5)
|
||||||
/* high value for this u32 */
|
/* high value for this u32 */
|
||||||
|
@ -2612,7 +2612,7 @@ static int define_te_avtab_helper(int which, avrule_t ** rule)
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
cur_perms->data |= 1U << (perdatum->s.value - 1);
|
cur_perms->data |= UINT32_C(1) << (perdatum->s.value - 1);
|
||||||
}
|
}
|
||||||
next:
|
next:
|
||||||
cur_perms = cur_perms->next;
|
cur_perms = cur_perms->next;
|
||||||
|
@ -3615,7 +3615,7 @@ int define_constraint(constraint_expr_t * expr)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node->permissions |= (1 << (perdatum->s.value - 1));
|
node->permissions |= (UINT32_C(1) << (perdatum->s.value - 1));
|
||||||
}
|
}
|
||||||
free(id);
|
free(id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue