]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
kmod_module: normalize module name
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 6 Dec 2011 04:46:22 +0000 (02:46 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 6 Dec 2011 05:34:51 +0000 (03:34 -0200)
libkmod/libkmod-module.c

index 152d8f64457aa96d4867cfefe0cff76925d860cc..9c8a627ab2a4aa42b8b26c06edbe99ca238973a0 100644 (file)
@@ -137,20 +137,21 @@ KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx,
 {
        struct kmod_module *m;
        size_t namelen;
+       char name_norm[NAME_MAX];
 
        if (ctx == NULL || name == NULL)
                return -ENOENT;
 
-       namelen = strlen(name) + 1;
+       path_to_modname(name, name_norm, &namelen);
 
-       m = calloc(1, sizeof(*m) + namelen);
+       m = calloc(1, sizeof(*m) + namelen + 1);
        if (m == NULL) {
                free(m);
                return -ENOMEM;
        }
 
        m->ctx = kmod_ref(ctx);
-       memcpy(m->name, name, namelen);
+       memcpy(m->name, name_norm, namelen + 1);
        m->refcount = 1;
 
        *mod = m;