]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
fix is_module_filename()
authorAleksey Makarov <amakarov@dev.rtsoft.ru>
Wed, 28 Nov 2012 03:44:00 +0000 (10:44 +0700)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 28 Nov 2012 13:22:00 +0000 (11:22 -0200)
modinfo fails if there is a ".ko" substring in the path to the module

libkmod/libkmod-util.c
libkmod/libkmod-util.h
tools/depmod.c
tools/modinfo.c

index b5a2588e8104ceb83b276c4a76d0dfd76e7ab7dd..05a26cc802e1ab53fc8f7cc3714471008d9ffd01 100644 (file)
@@ -308,6 +308,31 @@ char *path_make_absolute_cwd(const char *p)
        return r;
 }
 
+const struct kmod_ext kmod_exts[] = {
+       {".ko", sizeof(".ko") - 1},
+#ifdef ENABLE_ZLIB
+       {".ko.gz", sizeof(".ko.gz") - 1},
+#endif
+#ifdef ENABLE_XZ
+       {".ko.xz", sizeof(".ko.xz") - 1},
+#endif
+       {NULL, 0},
+};
+
+int path_ends_with_kmod_ext(const char *path, size_t len)
+{
+       const struct kmod_ext *eitr;
+
+       for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
+               if (len <= eitr->len)
+                       continue;
+               if (streq(path + len - eitr->len, eitr->ext))
+                       return true;
+       }
+
+       return false;
+}
+
 #define USEC_PER_SEC  1000000ULL
 #define NSEC_PER_USEC 1000ULL
 unsigned long long ts_usec(const struct timespec *ts)
index 5fe3e02e2737a761591183ef76ecab91a9eaac89..36192d9040aeab9016551894ded249e1ef1d4e2d 100644 (file)
@@ -22,6 +22,14 @@ char *path_make_absolute_cwd(const char *p) _must_check_ __attribute__((nonnull(
 int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) _must_check_ __attribute__((nonnull(1,2)));
 char *modname_normalize(const char *modname, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(1, 2)));
 char *path_to_modname(const char *path, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(2)));
+
+extern const struct kmod_ext {
+       const char *ext;
+       size_t len;
+} kmod_exts[];
+#define KMOD_EXT_UNC 0
+int path_ends_with_kmod_ext(const char *path, size_t len) __attribute__((nonnull(1)));
+
 unsigned long long stat_mstamp(const struct stat *st);
 unsigned long long ts_usec(const struct timespec *ts);
 
index 7bbdcd353e6319250a36ca6153770aabfb676950..de773918ae788c73daa7a30c96d36a28da227bc9 100644 (file)
 #define DEFAULT_VERBOSE LOG_WARNING
 static int verbose = DEFAULT_VERBOSE;
 
-#define KMOD_EXT_UNC 0
-
-static const struct kmod_ext {
-       const char *ext;
-       size_t len;
-} kmod_exts[] = {
-       {".ko", sizeof(".ko") - 1},
-#ifdef ENABLE_ZLIB
-       {".ko.gz", sizeof(".ko.gz") - 1},
-#endif
-#ifdef ENABLE_XZ
-       {".ko.xz", sizeof(".ko.xz") - 1},
-#endif
-       {NULL, 0},
-};
-
 static const char CFG_BUILTIN_KEY[] = "built-in";
 static const char *default_cfg_paths[] = {
        "/run/depmod.d",
@@ -1204,20 +1188,10 @@ static int depmod_modules_search_file(struct depmod *depmod, size_t baselen, siz
        struct mod *mod;
        const char *relpath;
        char modname[PATH_MAX];
-       const struct kmod_ext *eitr;
        size_t modnamelen;
-       uint8_t matches = 0;
        int err;
 
-       for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
-               if (namelen <= eitr->len)
-                       continue;
-               if (streq(path + baselen + namelen - eitr->len, eitr->ext)) {
-                       matches = 1;
-                       break;
-               }
-       }
-       if (!matches)
+       if (!path_ends_with_kmod_ext(path, baselen + namelen))
                return 0;
 
        if (path_to_modname(path, modname, &modnamelen) == NULL) {
@@ -2413,17 +2387,7 @@ static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *pa
                                                     path);
                        closedir(subdir);
                } else if (S_ISREG(st.st_mode)) {
-                       const struct kmod_ext *eitr;
-                       uint8_t matches = 0;
-                       for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
-                               if (namelen <= eitr->len)
-                                       continue;
-                               if (streq(name + namelen - eitr->len, eitr->ext)) {
-                                       matches = 1;
-                                       break;
-                               }
-                       }
-                       if (!matches)
+                       if (!path_ends_with_kmod_ext(path, namelen))
                                continue;
                        memcpy(path + baselen, name, namelen + 1);
                        err = st.st_mtime <= mtime;
index aec2608d5c1b349e6dde77b299eb69b7c6f289b0..17ed50d5ec36b2a99b26a2426b102670053c917c 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/utsname.h>
 #include <sys/stat.h>
 #include "libkmod.h"
+#include "libkmod-util.h"
 
 #include "kmod.h"
 
@@ -347,17 +348,10 @@ static void help(void)
 static bool is_module_filename(const char *name)
 {
        struct stat st;
-       const char *ptr;
 
        if (stat(name, &st) == 0 && S_ISREG(st.st_mode) &&
-                                       (ptr = strstr(name, ".ko")) != NULL) {
-               /*
-                * We screened for .ko; make sure this is either at the end of
-                * the name or followed by another '.' (e.g. gz or xz modules)
-                */
-               if(ptr[3] == '\0' || ptr[3] == '.')
+               path_ends_with_kmod_ext(name, strlen(name)))
                        return true;
-       }
 
        return false;
 }