kmodloader: fix open() error handling
authorJo-Philipp Wich <jow@openwrt.org>
Tue, 9 Feb 2016 07:53:28 +0000 (08:53 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 9 Feb 2016 07:53:31 +0000 (08:53 +0100)
Fixes kmodloader on systems without stdio and prevents fd leaks in case
descriptor zero is opened.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
kmodloader.c

index 387678a..86e3f44 100644 (file)
@@ -281,7 +281,7 @@ static struct module* get_module_info(const char *module, const char *name)
        struct module *m;
        struct stat s;
 
        struct module *m;
        struct stat s;
 
-       if (!fd) {
+       if (fd < 0) {
                ULOG_ERR("failed to open %s\n", module);
                return NULL;
        }
                ULOG_ERR("failed to open %s\n", module);
                return NULL;
        }
@@ -381,7 +381,7 @@ static int print_modinfo(char *module)
        struct stat s;
        char *map, *strings;
 
        struct stat s;
        char *map, *strings;
 
-       if (!fd) {
+       if (fd < 0) {
                ULOG_ERR("failed to open %s\n", module);
                return -1;
        }
                ULOG_ERR("failed to open %s\n", module);
                return -1;
        }
@@ -466,7 +466,7 @@ static int insert_module(char *path, const char *options)
        }
 
        fd = open(path, O_RDONLY);
        }
 
        fd = open(path, O_RDONLY);
-       if (!fd) {
+       if (fd < 0) {
                ULOG_ERR("cannot open %s\n", path);
                return ret;
        }
                ULOG_ERR("cannot open %s\n", path);
                return ret;
        }