Skip to content

Commit ac0fc6d

Browse files
cgzonesbachradsusi
authored andcommitted
libselinux/utils: drop reachable assert in sefcontext_compile
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 <lautrbach@redhat.com> Closes: https://lore.kernel.org/selinux/87jzchqck5.fsf@redhat.com/ Fixes: 92306da ("libselinux: rework selabel_file(5) database") Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Tested-by: Petr Lautrbach <lautrbach@redhat.com> Acked-by: James Carter <jwcart2@gmail.com>
1 parent d95931c commit ac0fc6d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libselinux/utils/sefcontext_compile.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab)
188188
if (len != 1)
189189
return -1;
190190

191+
if (stab->nel == 0)
192+
return 0;
193+
191194
/* sort entries by id */
192195
sids = calloc(stab->nel, sizeof(*sids));
193196
if (!sids)
@@ -203,8 +206,6 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab)
203206
}
204207
assert(index == stab->nel);
205208
qsort(sids, stab->nel, sizeof(struct security_id), security_id_compare);
206-
assert(sids[0].id == 1);
207-
assert(sids[stab->nel - 1].id == stab->nel);
208209

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

0 commit comments

Comments
 (0)