]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: Handle array memory issues
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 13 Aug 2024 17:33:00 +0000 (19:33 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 16 Aug 2024 04:59:49 +0000 (23:59 -0500)
If array operations fail, forward the error instead of silently
ignoring it and continuing the operation.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/68
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/depmod.c

index 94231aabff8ff1f777031d4644cbc16202d4cd77..dd18f9cab16d8d29529335fe0ed997d7802718cd 100644 (file)
@@ -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;