mirror of
https://github.com/SELinuxProject/selinux
synced 2025-02-07 13:21:45 +00:00
libsepol/cil: 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. This bug was found by the secilc-fuzzer. Signed-off-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
parent
14197e613c
commit
974da80e08
@ -1225,7 +1225,7 @@ int __perm_str_to_datum(char *perm_str, class_datum_t *sepol_class, uint32_t *da
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
*datum |= 1 << (sepol_perm->s.value - 1);
|
||||
*datum |= UINT32_C(1) << (sepol_perm->s.value - 1);
|
||||
|
||||
return SEPOL_OK;
|
||||
|
||||
@ -1523,7 +1523,7 @@ int cil_avrule_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_
|
||||
/* index of the u32 containing the permission */
|
||||
#define XPERM_IDX(x) (x >> 5)
|
||||
/* 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 */
|
||||
#define XPERM_LOW(x) (x << 5)
|
||||
/* high value for this u32 */
|
||||
@ -4760,7 +4760,7 @@ static struct cil_list *cil_classperms_from_sepol(policydb_t *pdb, uint16_t clas
|
||||
cil_list_init(&cp->perms, CIL_PERM);
|
||||
for (i = 0; i < sepol_class->permissions.nprim; i++) {
|
||||
struct cil_perm *perm;
|
||||
if ((data & (1 << i)) == 0) continue;
|
||||
if ((data & (UINT32_C(1) << i)) == 0) continue;
|
||||
perm = perm_value_to_cil[class][i+1];
|
||||
if (!perm) goto exit;
|
||||
cil_list_append(cp->perms, CIL_PERM, perm);
|
||||
|
Loading…
Reference in New Issue
Block a user