utils: use O_PATH when opening /dev
authorJo-Philipp Wich <jo@mein.io>
Tue, 17 May 2016 15:42:11 +0000 (17:42 +0200)
committerJohn Crispin <john@phrozen.org>
Tue, 17 May 2016 08:40:48 +0000 (10:40 +0200)
Use the O_PATH and O_DIRECTORY flags when opening the "/dev" path for the
subsequent openat() call to ensure that it is indeed a directory.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
utils/utils.c

index ebf5447c8dad94245a91e1749e9f1887cd3f8c94..e2e33963f217dc3ccb0df25691b520103fb9a5f7 100644 (file)
@@ -165,7 +165,7 @@ int patch_fd(const char *device, int fd, int flags)
                device = "/dev/null";
 
        if (*device != '/') {
-               dfd = open("/dev", O_RDONLY);
+               dfd = open("/dev", O_PATH|O_DIRECTORY);
 
                if (dfd < 0)
                        return -1;