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.
This commit is contained in:
Rich Felker 2014-10-30 20:08:40 -04:00
parent 9d836ea7a6
commit 2da3ab1382

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