Skip to contentSkip to conversation

libsepol: Use spaceship comparison operator when comparing ibpkeys

PATCH In review James Carter 2 participants 3 messages Aug 12 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: Use spaceship comparison operator when comparing ibpkeys

The comparsion function for ibpkeys in kernel_to_common subtracts the subnet_prefixes of the two ibpkeys which are unsigned 64-bit values and stores the result in an int which might not be able to contain the result.

Use the spaceship comparison operator to compare the subnet_prefxes to avoid any issues.

---
 libsepol/src/kernel_to_common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
libsepol/src/kernel_to_common.c +2 -1
index 338dcef6..f338b588 100644
@@ -585,7 +585,8 @@ static int ibpkey_data_cmp(const void *a, const void *b)
 	struct ocontext *const *aa = a;
 	struct ocontext *const *bb = b;
 
-	rc = (*aa)->u.ibpkey.subnet_prefix - (*bb)->u.ibpkey.subnet_prefix;
+	rc = spaceship_cmp((*aa)->u.ibpkey.subnet_prefix,
+			   (*bb)->u.ibpkey.subnet_prefix);
 	if (rc)
 		return rc;
 
Signature · 1 line
2.55.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · James Carter

The comparsion function for ibpkeys in kernel_to_common subtracts the subnet_prefixes of the two ibpkeys which are unsigned 64-bit values and stores the result in an int which might not be able to contain the result.

Use the spaceship comparison operator to compare the subnet_prefxes to avoid any issues.

maintainer
#2 lore raw
Quoted 8 lines · Stephen Smalley
Quoted 6 lines · James Carter

The comparsion function for ibpkeys in kernel_to_common subtracts the subnet_prefixes of the two ibpkeys which are unsigned 64-bit values and stores the result in an int which might not be able to contain the result.

Quoted 6 lines
Quoted 4 lines

Use the spaceship comparison operator to compare the subnet_prefxes to avoid any issues.

Thanks, merged.