Skip to content

Commit

Permalink
libselinux: Fix integer comparison issues when compiling for 32-bit
Browse files Browse the repository at this point in the history
Trying to compile libselinux for 32-bit produces the following error:

selinux_restorecon.c:1194:31: error: comparison of integer expressions of different signedness: ‘__fsword_t’ {aka ‘int’} and ‘unsigned int’ [-Werror=sign-compare]
 1194 |         if (state.sfsb.f_type == RAMFS_MAGIC || state.sfsb.f_type == TMPFS_MAGIC ||
      |                               ^~

Since RAMFS_MAGIC = 0x858458f6 == 2240043254, which > 2^31, but < 2^32,
cast both as uint32_t for the comparison.

Reported-by: Daniel Schepler
Signed-off-by: James Carter <[email protected]>
Reviewed-by: Christian Göttsche <[email protected]>
  • Loading branch information
jwcart2 authored and stephensmalley committed Jul 30, 2024
1 parent 84a33fb commit 51545d6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libselinux/src/selinux_restorecon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,8 +1191,8 @@ static int selinux_restorecon_common(const char *pathname_orig,
}

/* Skip digest on in-memory filesystems and /sys */
if (state.sfsb.f_type == RAMFS_MAGIC || state.sfsb.f_type == TMPFS_MAGIC ||
state.sfsb.f_type == SYSFS_MAGIC)
if ((uint32_t)state.sfsb.f_type == (uint32_t)RAMFS_MAGIC ||
state.sfsb.f_type == TMPFS_MAGIC || state.sfsb.f_type == SYSFS_MAGIC)
state.setrestorecondigest = false;

if (state.flags.set_xdev)
Expand Down Expand Up @@ -1490,7 +1490,7 @@ int selinux_restorecon_xattr(const char *pathname, unsigned int xattr_flags,

if (!recurse) {
if (statfs(pathname, &sfsb) == 0) {
if (sfsb.f_type == RAMFS_MAGIC ||
if ((uint32_t)sfsb.f_type == (uint32_t)RAMFS_MAGIC ||
sfsb.f_type == TMPFS_MAGIC)
return 0;
}
Expand Down Expand Up @@ -1525,7 +1525,7 @@ int selinux_restorecon_xattr(const char *pathname, unsigned int xattr_flags,
continue;
case FTS_D:
if (statfs(ftsent->fts_path, &sfsb) == 0) {
if (sfsb.f_type == RAMFS_MAGIC ||
if ((uint32_t)sfsb.f_type == (uint32_t)RAMFS_MAGIC ||
sfsb.f_type == TMPFS_MAGIC)
continue;
}
Expand Down

0 comments on commit 51545d6

Please sign in to comment.