Skip to content

Commit

Permalink
libselinux/utils: drop reachable assert in sefcontext_compile
Browse files Browse the repository at this point in the history
The two asserts following qsort(3) where useful during development to
ensure the comparison function and the corresponding pointer handling
were correct.  They however do not take into account an empty file
context definition file containing no definitions and thus `stab->nel`
being NULL.  Drop the two asserts.

Also return early to not depend on whether calloc(3) called with a size
of zero returns NULL or a special value.

Reported-by: Petr Lautrbach <[email protected]>
Closes: https://lore.kernel.org/selinux/[email protected]/
Fixes: 92306da ("libselinux: rework selabel_file(5) database")
Signed-off-by: Christian Göttsche <[email protected]>
Tested-by: Petr Lautrbach <[email protected]>
Acked-by: James Carter <[email protected]>
  • Loading branch information
cgzones authored and bachradsusi committed Dec 4, 2024
1 parent d95931c commit ac0fc6d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libselinux/utils/sefcontext_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab)
if (len != 1)
return -1;

if (stab->nel == 0)
return 0;

/* sort entries by id */
sids = calloc(stab->nel, sizeof(*sids));
if (!sids)
Expand All @@ -203,8 +206,6 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab)
}
assert(index == stab->nel);
qsort(sids, stab->nel, sizeof(struct security_id), security_id_compare);
assert(sids[0].id == 1);
assert(sids[stab->nel - 1].id == stab->nel);

/* write raw contexts sorted by id */
for (uint32_t i = 0; i < stab->nel; i++) {
Expand Down

0 comments on commit ac0fc6d

Please sign in to comment.