Explorar el Código

fix invalid access by openat to possibly-missing variadic mode argument

the mode argument is only required to be present when the O_CREAT or
O_TMPFILE flag is used.
Rich Felker hace 10 años
padre
commit
2da3ab1382
Se han modificado 1 ficheros con 8 adiciones y 4 borrados
  1. 8 4
      src/fcntl/openat.c

+ 8 - 4
src/fcntl/openat.c

@@ -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);
 }