fix invalid access by openat to possibly-missing variadic mode argument
authorRich Felker <dalias@aerifal.cx>
Fri, 31 Oct 2014 00:08:40 +0000 (20:08 -0400)
committerRich Felker <dalias@aerifal.cx>
Fri, 31 Oct 2014 00:11:04 +0000 (20:11 -0400)
the mode argument is only required to be present when the O_CREAT or
O_TMPFILE flag is used.

src/fcntl/openat.c

index 634c4bf..4faeb29 100644 (file)
@@ -6,10 +6,14 @@
 int openat(int fd, const char *filename, int flags, ...)
 {
        mode_t mode;
-       va_list ap;
-       va_start(ap, flags);
-       mode = va_arg(ap, mode_t);
-       va_end(ap);
+
+       if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
+               va_list ap;
+               va_start(ap, flags);
+               mode = va_arg(ap, mode_t);
+               va_end(ap);
+       }
+
        return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode);
 }