[PATCH] libsepol: Use spaceship comparison operator when comparing ibpkeys
James Carter <[email protected]>
| Newsgroups | org.kernel.vger.selinux |
|---|---|
| Message-ID | <[email protected]> |
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. Signed-off-by: James Carter <[email protected]> --- libsepol/src/kernel_to_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libsepol/src/kernel_to_common.c b/libsepol/src/kernel_to_common.c index 338dcef6..f338b588 100644 --- a/libsepol/src/kernel_to_common.c +++ b/libsepol/src/kernel_to_common.c @@ -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; -- 2.55.0