]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
always normalize user-given alias.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sat, 10 Dec 2011 23:00:19 +0000 (21:00 -0200)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sun, 11 Dec 2011 22:58:22 +0000 (20:58 -0200)
libkmod/libkmod-module.c
libkmod/libkmod-private.h
libkmod/libkmod.c

index 738c3f3f6ddb230473330d4ac77a88ff63730dcf..ca25bc74bfd503496a295b4a61331815460c61b2 100644 (file)
@@ -60,7 +60,7 @@ struct kmod_module {
        char name[];
 };
 
-static inline char *modname_normalize(const char *modname, char buf[NAME_MAX],
+inline char *modname_normalize(const char *modname, char buf[NAME_MAX],
                                                                size_t *len)
 {
        size_t s;
@@ -318,10 +318,11 @@ KMOD_EXPORT struct kmod_module *kmod_module_ref(struct kmod_module *mod)
        } while (0)
 
 KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx,
-                                               const char *alias,
+                                               const char *given_alias,
                                                struct kmod_list **list)
 {
        int err;
+       char alias[NAME_MAX];
 
        if (ctx == NULL || alias == NULL)
                return -ENOENT;
@@ -331,6 +332,8 @@ KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx,
                return -ENOSYS;
        }
 
+       modname_normalize(given_alias, alias, NULL);
+
        /* Aliases from config file override all the others */
        err = kmod_lookup_alias_from_config(ctx, alias, list);
        CHECK_ERR_AND_FINISH(err, fail, list, finish);
index eb98ddc2f62b872d74f142d08b6ca13ade526cc6..ce829643577429bea4075c9a86f1d9bfb52f88e9 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <syslog.h>
+#include <limits.h>
 
 #include "macro.h"
 #include "libkmod.h"
@@ -103,6 +104,7 @@ const char *kmod_command_get_modname(const struct kmod_list *l) __attribute__((n
 
 
 /* libkmod-module.c */
+char *modname_normalize(const char *modname, char buf[NAME_MAX], size_t *len)  __attribute__((nonnull(1, 2)));
 int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2)));
 
 /* libkmod-hash.c */
index 59ed81b74c465324b578ff05c87bf119fd26610d..4ff6d342f8dc379c82af54ceb883d7d35110f61f 100644 (file)
@@ -623,9 +623,10 @@ KMOD_EXPORT void kmod_unload_resources(struct kmod_ctx *ctx)
        }
 }
 
-KMOD_EXPORT int kmod_resolve_alias_options(struct kmod_ctx *ctx, const char *alias, char **options)
+KMOD_EXPORT int kmod_resolve_alias_options(struct kmod_ctx *ctx, const char *given_alias, char **options)
 {
        struct kmod_list *modules = NULL, *l;
+       char alias[NAME_MAX];
        char *opts = NULL;
        size_t optslen = 0;
        int err;
@@ -633,6 +634,8 @@ KMOD_EXPORT int kmod_resolve_alias_options(struct kmod_ctx *ctx, const char *ali
        if (ctx == NULL || options == NULL)
                return -ENOENT;
 
+       modname_normalize(given_alias, alias, NULL);
+
        err = kmod_module_new_from_lookup(ctx, alias, &modules);
        if (err >= 0) {
                kmod_list_foreach(l, modules) {