ujail: add O_CLOEXEC flag to open() call
authorEtienne CHAMPETIER <champetier.etienne@gmail.com>
Mon, 30 Nov 2015 23:09:20 +0000 (23:09 +0000)
committerJohn Crispin <blogic@openwrt.org>
Fri, 11 Dec 2015 10:58:33 +0000 (11:58 +0100)
if we forget to close() in the future,
this prevent fd leak

Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
jail/elf.c
jail/fs.c

index b8f2cc5..7c6076a 100644 (file)
@@ -81,7 +81,7 @@ int lib_open(char **fullpath, const char *file)
 
        list_for_each_entry(p, &library_paths, list) {
                snprintf(path, sizeof(path), "%s/%s", p->path, file);
-               fd = open(path, O_RDONLY);
+               fd = open(path, O_RDONLY|O_CLOEXEC);
                if (fd >= 0) {
                        *fullpath = strdup(path);
                        break;
index 7b7b820..f390180 100644 (file)
--- a/jail/fs.c
+++ b/jail/fs.c
@@ -116,7 +116,7 @@ int add_path_and_deps(const char *path, int readonly, int error, int lib)
        if (path[0] == '/') {
                if (avl_find(&mounts, path))
                        return 0;
-               fd = open(path, O_RDONLY);
+               fd = open(path, O_RDONLY|O_CLOEXEC);
                if (fd == -1)
                        return error;
                add_mount(path, readonly, error);