Skip to content

Commit 2cd92f7

Browse files
committed
libsemanage: do not sort empty records
Do not sort empty records to avoid calling qsort(3) with a NULL pointer. Signed-off-by: Christian Göttsche <[email protected]>
1 parent fe7021b commit 2cd92f7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

libsemanage/src/database_join.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ static int dbase_join_cache(semanage_handle_t * handle, dbase_join_t * dbase)
7777
goto err;
7878

7979
/* Sort for quicker merge later */
80-
qsort(records1, rcount1, sizeof(record1_t *),
81-
(int (*)(const void *, const void *))rtable1->compare2_qsort);
82-
qsort(records2, rcount2, sizeof(record2_t *),
83-
(int (*)(const void *, const void *))rtable2->compare2_qsort);
80+
if (rcount1 > 0)
81+
qsort(records1, rcount1, sizeof(record1_t *),
82+
(int (*)(const void *, const void *))rtable1->compare2_qsort);
83+
if (rcount2 > 0)
84+
qsort(records2, rcount2, sizeof(record2_t *),
85+
(int (*)(const void *, const void *))rtable2->compare2_qsort);
8486

8587
/* Now merge into this dbase */
8688
while (i < rcount1 || j < rcount2) {

0 commit comments

Comments
 (0)