libsepol: ensure transitivity in compare functions

Ensure comparison functions used by qsort(3) fulfill transitivity, since
otherwise the resulting array might not be sorted correctly or worse[1]
in case of integer overflows.

[1]: https://www.qualys.com/2024/01/30/qsort.txt

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Christian Göttsche 2024-01-31 13:56:10 +01:00 committed by James Carter
parent 3dc1116992
commit b52e27aeaa
2 changed files with 2 additions and 2 deletions

View File

@ -503,7 +503,7 @@ static int ibendport_data_cmp(const void *a, const void *b)
if (rc)
return rc;
return (*aa)->u.ibendport.port - (*bb)->u.ibendport.port;
return spaceship_cmp((*aa)->u.ibendport.port, (*bb)->u.ibendport.port);
}
static int pirq_data_cmp(const void *a, const void *b)

View File

@ -1681,7 +1681,7 @@ static int class_perm_cmp(const void *a, const void *b)
const struct class_perm_datum *aa = a;
const struct class_perm_datum *bb = b;
return aa->val - bb->val;
return spaceship_cmp(aa->val, bb->val);
}
static int common_to_cil(char *key, void *data, void *UNUSED(arg))