summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2017-08-30 15:09:49 +0200
committerHans Dedecker <dedeckeh@gmail.com>2017-08-31 11:44:38 +0200
commitf1ef2c311d5bc4d0e1bae60df774899db5611cc9 (patch)
tree92df4fd0ab8b7b6a284332b78b1052293421177c
parent9cb63df9b905e735c718d582b1d65cdff383cbd3 (diff)
downloadubox-f1ef2c311d5bc4d0e1bae60df774899db5611cc9.tar.gz
kmodloader: fix possible segfaults
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r--kmodloader.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/kmodloader.c b/kmodloader.c
index a4d492d..3dc7665 100644
--- a/kmodloader.c
+++ b/kmodloader.c
@@ -563,6 +563,9 @@ static int insert_module(char *path, const char *options)
}
data = malloc(s.st_size);
+ if (!data)
+ goto out;
+
if (read(fd, data, s.st_size) == s.st_size) {
ret = syscall(__NR_init_module, data, (unsigned long) s.st_size, options);
if (errno == EEXIST)
@@ -571,6 +574,7 @@ static int insert_module(char *path, const char *options)
else
ULOG_ERR("failed to read full module %s\n", path);
+out:
close(fd);
free(data);
@@ -692,6 +696,11 @@ static int main_insmod(int argc, char **argv)
len += strlen(argv[i]) + 1;
options = malloc(len);
+ if (!options) {
+ ret = -1;
+ goto err;
+ }
+
options[0] = 0;
cur = options;
for (i = 2; i < argc; i++) {
@@ -897,6 +906,9 @@ static int main_loader(int argc, char **argv)
dir = argv[1];
path = malloc(strlen(dir) + 2);
+ if (!path)
+ return -1;
+
strcpy(path, dir);
strcat(path, "*");