summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2017-08-30 13:32:43 +0200
committerHans Dedecker <dedeckeh@gmail.com>2017-08-31 13:45:04 +0200
commitf346111d733671a03b49fe56cf1616723fc63974 (patch)
treebc9794cbf00ce92265ba8de73dae43fb07990399
parentf1ef2c311d5bc4d0e1bae60df774899db5611cc9 (diff)
downloadubox-f346111d733671a03b49fe56cf1616723fc63974.tar.gz
kmodloader: lift restriction on module alias info
kmodloader has a restriction of storing only 32 aliases for a given module; as modules can have easily more than 32 aliases let's remove the restriction by using a dynamic allocation mechanism when retrieving the aliases. While at it also check the get_module_info return value setting an error code in case NULL is returned. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r--kmodloader.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/kmodloader.c b/kmodloader.c
index 3dc7665..94cfc42 100644
--- a/kmodloader.c
+++ b/kmodloader.c
@@ -340,7 +340,7 @@ static struct module* get_module_info(const char *module, const char *name)
int fd = open(module, O_RDONLY);
unsigned int offset, size;
char *map = MAP_FAILED, *strings, *dep = NULL;
- const char *aliases[32] = { 0 };
+ const char **aliases = NULL;
int naliases = 0;
struct module *m = NULL;
struct stat s;
@@ -383,11 +383,13 @@ static struct module* get_module_info(const char *module, const char *name)
if (!strncmp(strings, "depends=", len + 1))
dep = sep;
else if (!strncmp(strings, "alias=", len + 1)) {
- if (naliases < ARRAY_SIZE(aliases))
- aliases[naliases++] = sep;
- else
- ULOG_WARN("module %s has more than %d aliases: truncated",
- name, ARRAY_SIZE(aliases));
+ aliases = realloc(aliases, sizeof(sep) * (naliases + 1));
+ if (!aliases) {
+ ULOG_ERR("out of memory\n");
+ goto out;
+ }
+
+ aliases[naliases++] = sep;
}
strings = &sep[strlen(sep)];
}
@@ -404,6 +406,8 @@ out:
if (fd >= 0)
close(fd);
+ free(aliases);
+
return m;
}
@@ -413,7 +417,7 @@ static int scan_module_folder(const char *dir)
struct utsname ver;
char *path;
glob_t gl;
- int j;
+ int j, rv = 0;
uname(&ver);
path = alloca(strlen(dir) + sizeof("*.ko") + 1);
@@ -430,13 +434,15 @@ static int scan_module_folder(const char *dir)
continue;
m = find_module(name);
- if (!m)
- get_module_info(gl.gl_pathv[j], name);
+ if (!m) {
+ if (!get_module_info(gl.gl_pathv[j], name))
+ rv |= -1;
+ }
}
globfree(&gl);
- return 0;
+ return rv;
}
static int scan_module_folders(void)