@@ -77,10 +77,10 @@ static int dbase_join_cache(semanage_handle_t * handle, dbase_join_t * dbase)
goto err;
/* Sort for quicker merge later */
- if (rcount1 > 0) {
+ if (rcount1 > 1) {
qsort(records1, rcount1, sizeof(record1_t *), rtable1->compare2_qsort);
}
- if (rcount2 > 0) {
+ if (rcount2 > 1) {
qsort(records2, rcount2, sizeof(record2_t *), rtable2->compare2_qsort);
}
@@ -89,7 +89,8 @@ int semanage_ibendport_validate_local(semanage_handle_t *handle)
if (semanage_ibendport_list_local(handle, &ibendports, &nibendports) < 0)
goto err;
- qsort(ibendports, nibendports, sizeof(semanage_ibendport_t *), semanage_ibendport_compare2_qsort);
+ if (nibendports > 1)
+ qsort(ibendports, nibendports, sizeof(semanage_ibendport_t *), semanage_ibendport_compare2_qsort);
/* Test each ibendport */
while (i < nibendports) {
@@ -91,7 +91,8 @@ int semanage_ibpkey_validate_local(semanage_handle_t *handle)
if (semanage_ibpkey_list_local(handle, &ibpkeys, &nibpkeys) < 0)
goto err;
- qsort(ibpkeys, nibpkeys, sizeof(semanage_ibpkey_t *), semanage_ibpkey_compare2_qsort);
+ if (nibpkeys > 1)
+ qsort(ibpkeys, nibpkeys, sizeof(semanage_ibpkey_t *), semanage_ibpkey_compare2_qsort);
/* Test each ibpkey for overlap */
while (i < nibpkeys) {
@@ -168,7 +168,7 @@ int semanage_base_merge_components(semanage_handle_t * handle)
goto err;
/* Sort records on MODE_SORT */
- if (mode & MODE_SORT) {
+ if ((mode & MODE_SORT) && nrecords > 1) {
qsort(records, nrecords, sizeof(record_t *), rtable->compare2_qsort);
}
@@ -82,7 +82,9 @@ int semanage_port_validate_local(semanage_handle_t * handle)
/* List and sort the ports */
if (semanage_port_list_local(handle, &ports, &nports) < 0)
goto err;
- qsort(ports, nports, sizeof(semanage_port_t *), semanage_port_compare2_qsort);
+
+ if (nports > 1)
+ qsort(ports, nports, sizeof(semanage_port_t *), semanage_port_compare2_qsort);
/* Test each port for overlap */
while (i < nports) {
@@ -167,7 +167,7 @@ int semanage_list_sort(semanage_list_t ** l)
size_t count = 0;
size_t i = 0;
- if (!l)
+ if (!l || !(*l)->next)
return 0;
for (temp = *l; temp; temp = temp->next)