Add safety NULL checks in exported functions
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 55ac1d2..79a49c3 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -221,7 +221,7 @@
char name_norm[NAME_MAX];
char *namesep;
- if (ctx == NULL || name == NULL)
+ if (ctx == NULL || name == NULL || mod == NULL)
return -ENOENT;
alias_normalize(name, name_norm, &namelen);
@@ -317,7 +317,7 @@
char *abspath;
size_t namelen;
- if (ctx == NULL || path == NULL)
+ if (ctx == NULL || path == NULL || mod == NULL)
return -ENOENT;
abspath = path_make_absolute_cwd(path);
@@ -599,6 +599,9 @@
*/
KMOD_EXPORT const char *kmod_module_get_name(const struct kmod_module *mod)
{
+ if (mod == NULL)
+ return NULL;
+
return mod->name;
}
@@ -617,6 +620,9 @@
{
char *line;
+ if (mod == NULL)
+ return NULL;
+
DBG(mod->ctx, "name='%s' path='%s'\n", mod->name, mod->path);
if (mod->path != NULL)
@@ -1051,6 +1057,9 @@
char path[PATH_MAX], buf[32];
int fd, err, pathlen;
+ if (mod == NULL)
+ return -ENOENT;
+
pathlen = snprintf(path, sizeof(path),
"/sys/module/%s/initstate", mod->name);
fd = open(path, O_RDONLY);
@@ -1160,6 +1169,9 @@
long refcnt;
int fd, err;
+ if (mod == NULL)
+ return -ENOENT;
+
snprintf(path, sizeof(path), "/sys/module/%s/refcnt", mod->name);
fd = open(path, O_RDONLY);
if (fd < 0) {
@@ -1197,6 +1209,7 @@
if (mod == NULL)
return NULL;
+
snprintf(dname, sizeof(dname), "/sys/module/%s/holders", mod->name);
d = opendir(dname);