From: Tobias Stoeckmann Date: Fri, 18 Oct 2024 15:37:40 +0000 (+0200) Subject: depmod: Prevent undefined behavior X-Git-Tag: v34~199 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d056ac221b2b944307b561bbfc35e5fb3f782e1d;p=thirdparty%2Fkmod.git depmod: Prevent undefined behavior Calling qsort with NULL argument is invalid, although size 0 would prevent anything bad from happening. Make sure that UBSAN is not triggered. Signed-off-by: Tobias Stoeckmann Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/193 Signed-off-by: Lucas De Marchi --- diff --git a/tools/depmod.c b/tools/depmod.c index 3328103e..42cc0a21 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -1494,10 +1494,12 @@ static void depmod_modules_sort(struct depmod *depmod) mod->sort_idx = i++; } - array_sort(&depmod->modules, mod_cmp); - for (idx = 0; idx < depmod->modules.count; idx++) { - struct mod *m = depmod->modules.array[idx]; - m->idx = idx; + if (depmod->modules.count > 1) { + array_sort(&depmod->modules, mod_cmp); + for (idx = 0; idx < depmod->modules.count; idx++) { + struct mod *m = depmod->modules.array[idx]; + m->idx = idx; + } } corrupted: