Module Name: src Committed By: manu Date: Thu Jan 31 02:27:06 UTC 2019
Modified Files: src/sys/kern: vfs_syscalls.c Log Message: Do not resolve fdat for openat(2) if path is absolute Opengroup says "The openat() function shall be equivalent to the open() function except in the case where path specifies a relative path", but says nothing about fdat usage when path is absolute; https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html We used to always reslove fdat, leading to error if it was invalid (e.g.: -1). That caused portability problem with other systems that just ignore it. See discussion in a pull request to work around that problem with MariaDB: https://github.com/MariaDB/server/pull/838 We fix the problem by ignoring fdat when path is absolute. To generate a diff of this commit: cvs rdiff -u -r1.520 -r1.521 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.520 src/sys/kern/vfs_syscalls.c:1.521 --- src/sys/kern/vfs_syscalls.c:1.520 Tue Jan 29 09:28:50 2019 +++ src/sys/kern/vfs_syscalls.c Thu Jan 31 02:27:06 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.520 2019/01/29 09:28:50 pgoyette Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.521 2019/01/31 02:27:06 manu Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.520 2019/01/29 09:28:50 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.521 2019/01/31 02:27:06 manu Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -1631,6 +1631,7 @@ do_sys_openat(lwp_t *l, int fdat, const file_t *dfp = NULL; struct vnode *dvp = NULL; struct pathbuf *pb; + const char *pathstring = NULL; int error; if (path == NULL) { @@ -1643,7 +1644,14 @@ do_sys_openat(lwp_t *l, int fdat, const return error; } - if (fdat != AT_FDCWD) { + pathstring = pathbuf_stringcopy_get(pb); + + /* + * fdat is ignored if: + * 1) if fdat is AT_FDCWD, which means use current directory as base. + * 2) if path is absolute, then fdat is useless. + */ + if (fdat != AT_FDCWD && pathstring[0] != '/') { /* fd_getvnode() will use the descriptor for us */ if ((error = fd_getvnode(fdat, &dfp)) != 0) goto out; @@ -1656,6 +1664,7 @@ do_sys_openat(lwp_t *l, int fdat, const if (dfp != NULL) fd_putfile(fdat); out: + pathbuf_stringcopy_put(pb, pathstring); pathbuf_destroy(pb); return error; }