os layer qsort

Jouni Malinen j at w1.fi
Fri Oct 7 15:07:19 PDT 2016

On Fri, Oct 07, 2016 at 04:28:06PM -0500, Joel Cunningham wrote:
> I’ve run into an issue with hostap running on an embedded platform.  The qsort function from the standard C library data aborts when the list size is 0.  We’ve seen this happen in wpa_supplicant_get_scan_results() with a zero-sized scan results.  A zero-sized can results is probably not common, but this could be encountered with a device in an isolation chamber.

Can you identify the C library used here? It does not sound like it
would be standards compliant if it asserts on the second argument to
qsort() being 0. That is supposed to result in no calls to the
comparison function and no rearrangement..

> I’m wondering if the preferred solution is to introduce os_qsort in to the os.h abstraction layer that way I can add extra checks on the size before calling qsort.  I’m kind of surprised there isn’t an abstracted call already since qsort is typically implemented in the standard C library and would fall under the OS_N_C_LIB_DEFINE feature.

This is the first time I've seen a report pointing out issues with
qsort().. To be honest, I'd rather have that C library fixed than add
workarounds in wpa_supplicant unless someone can point to a C standard
that claims the behavior in that library implementation being allowed.

There is obviously no need to call qsort() if there is less than two
entries in the array, so it would be trivial to skip those calls. I'm
not sure using an os_qsort() wrapper would be the best approach here,

Jouni Malinen                                            PGP id EFC895FA

More information about the Hostap mailing list