From: Tobias Stoeckmann Date: Tue, 13 Aug 2024 17:33:00 +0000 (+0200) Subject: depmod: Handle array memory issues X-Git-Tag: v34~514 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=251654320ccdfeba3ef083b512eaaa68bf8e8cbc;p=thirdparty%2Fkmod.git depmod: Handle array memory issues If array operations fail, forward the error instead of silently ignoring it and continuing the operation. Signed-off-by: Tobias Stoeckmann Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/68 Signed-off-by: Lucas De Marchi --- diff --git a/tools/depmod.c b/tools/depmod.c index 94231aab..dd18f9ca 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -929,8 +929,11 @@ static int mod_add_dependency(struct mod *mod, struct symbol *sym) err = array_append_unique(&mod->deps, sym->owner); if (err == -EEXIST) return 0; - if (err < 0) + if (err < 0) { + CRIT("failed to add symbol %s to module %s: %s\n", + sym->name, mod->path, strerror(-err)); return err; + } sym->owner->users++; SHOW("%s needs \"%s\": %s\n", mod->path, sym->name, sym->owner->path); @@ -1581,6 +1584,7 @@ static int depmod_load_module_dependencies(struct depmod *depmod, struct mod *mo { const struct cfg *cfg = depmod->cfg; struct kmod_list *l; + int ret = 0; DBG("do dependencies of %s\n", mod->path); kmod_list_foreach(l, mod->dep_sym_list) { @@ -1589,6 +1593,7 @@ static int depmod_load_module_dependencies(struct depmod *depmod, struct mod *mo int bindtype = kmod_module_dependency_symbol_get_bind(l); struct symbol *sym = depmod_symbol_find(depmod, name); uint8_t is_weak = bindtype == KMOD_SYMBOL_WEAK; + int err; if (sym == NULL) { DBG("%s needs (%c) unknown symbol %s\n", @@ -1607,15 +1612,18 @@ static int depmod_load_module_dependencies(struct depmod *depmod, struct mod *mo mod->path, name); } - mod_add_dependency(mod, sym); + err = mod_add_dependency(mod, sym); + if (err < 0) + ret = err; } - return 0; + return ret; } static int depmod_load_dependencies(struct depmod *depmod) { struct mod **itr, **itr_end; + int ret = 0; DBG("load dependencies (%zd modules, %u symbols)\n", depmod->modules.count, hash_get_count(depmod->symbols)); @@ -1624,19 +1632,22 @@ static int depmod_load_dependencies(struct depmod *depmod) itr_end = itr + depmod->modules.count; for (; itr < itr_end; itr++) { struct mod *mod = *itr; + int err; if (mod->dep_sym_list == NULL) { DBG("ignoring %s: no dependency symbols\n", mod->path); continue; } - depmod_load_module_dependencies(depmod, mod); + err = depmod_load_module_dependencies(depmod, mod); + if (err < 0) + ret = err; } DBG("loaded dependencies (%zd modules, %u symbols)\n", depmod->modules.count, hash_get_count(depmod->symbols)); - return 0; + return ret; } static int dep_cmp(const void *pa, const void *pb) @@ -1706,7 +1717,9 @@ static int depmod_report_one_cycle(struct depmod *depmod, v = v->parent, n++) { sz += v->mod->modnamesz - 1; - array_append(&reverse, v); + rc = array_append(&reverse, v); + if (rc < 0) + return rc; rc = hash_add(loop_set, v->mod->modname, NULL); if (rc != 0) return rc;