fix fd leak race (missing O_CLOEXEC) in fchmodat
authorRich Felker <dalias@aerifal.cx>
Thu, 5 Feb 2015 03:50:40 +0000 (22:50 -0500)
committerRich Felker <dalias@aerifal.cx>
Mon, 30 Mar 2015 05:41:34 +0000 (01:41 -0400)
(cherry picked from commit 2736eb6caa70bb6e909d7d8ebbe145c2071435e0)

src/stat/fchmodat.c

index 12e7ff0cd17f90209cfb979c7a7096e2767e052a..94d0335c06417e897efb662a9f798f2afbb24d7f 100644 (file)
@@ -21,7 +21,7 @@ int fchmodat(int fd, const char *path, mode_t mode, int flag)
        if (S_ISLNK(st.st_mode))
                return __syscall_ret(-EOPNOTSUPP);
 
-       if ((fd2 = __syscall(SYS_openat, fd, path, O_RDONLY|O_PATH|O_NOFOLLOW|O_NOCTTY)) < 0) {
+       if ((fd2 = __syscall(SYS_openat, fd, path, O_RDONLY|O_PATH|O_NOFOLLOW|O_NOCTTY|O_CLOEXEC)) < 0) {
                if (fd2 == -ELOOP)
                        return __syscall_ret(-EOPNOTSUPP);
                return __syscall_ret(fd2);