Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Do not resolve fdat for openat(2) if path is absolute



details:   https://anonhg.NetBSD.org/src/rev/6edbebf7f6f2
branches:  trunk
changeset: 448020:6edbebf7f6f2
user:      manu <manu%NetBSD.org@localhost>
date:      Thu Jan 31 02:27:06 2019 +0000

description:
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.

diffstat:

 sys/kern/vfs_syscalls.c |  15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diffs (50 lines):

diff -r 5cbd53560654 -r 6edbebf7f6f2 sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c   Thu Jan 31 01:49:28 2019 +0000
+++ b/sys/kern/vfs_syscalls.c   Thu Jan 31 02:27:06 2019 +0000
@@ -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 @@
        file_t *dfp = NULL;
        struct vnode *dvp = NULL;
        struct pathbuf *pb;
+       const char *pathstring = NULL;
        int error;
 
        if (path == NULL) {
@@ -1643,7 +1644,14 @@
                        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 @@
        if (dfp != NULL)
                fd_putfile(fdat);
 out:
+       pathbuf_stringcopy_put(pb, pathstring);
        pathbuf_destroy(pb);
        return error;
 }



Home | Main Index | Thread Index | Old Index