From 801720e63b20e3b8215764ff0d68a29534ca7e62 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Thu, 29 Oct 2009 21:33:26 -0700 Subject: [PATCH] Fix compat handling in *at functions. When passed an empty string for the filename, the compat code using /proc in all *at functions did the wrong thing. --- ChangeLog | 21 +++++++++++++++++++++ sysdeps/unix/sysv/linux/faccessat.c | 8 +++++++- sysdeps/unix/sysv/linux/fchmodat.c | 8 +++++++- sysdeps/unix/sysv/linux/fchownat.c | 8 +++++++- sysdeps/unix/sysv/linux/futimesat.c | 8 +++++++- sysdeps/unix/sysv/linux/fxstatat.c | 8 +++++++- sysdeps/unix/sysv/linux/fxstatat64.c | 8 +++++++- sysdeps/unix/sysv/linux/i386/fchownat.c | 8 +++++++- sysdeps/unix/sysv/linux/i386/fxstatat.c | 8 +++++++- sysdeps/unix/sysv/linux/linkat.c | 8 +++++++- sysdeps/unix/sysv/linux/mkdirat.c | 8 +++++++- sysdeps/unix/sysv/linux/openat.c | 8 +++++++- sysdeps/unix/sysv/linux/powerpc/fchownat.c | 8 +++++++- sysdeps/unix/sysv/linux/readlinkat.c | 8 +++++++- sysdeps/unix/sysv/linux/renameat.c | 14 +++++++++++++- sysdeps/unix/sysv/linux/symlinkat.c | 8 +++++++- sysdeps/unix/sysv/linux/unlinkat.c | 8 +++++++- sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c | 8 +++++++- sysdeps/unix/sysv/linux/xmknodat.c | 8 +++++++- 19 files changed, 153 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8bbc93c..593de06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,26 @@ 2009-10-29 Ulrich Drepper + [BZ #10609] + * sysdeps/unix/sysv/linux/faccessat.c: Fix handling of empty parameters + for file names in case the syscall is not available. + * sysdeps/unix/sysv/linux/fchmodat.c: Likewise. + * sysdeps/unix/sysv/linux/fchownat.c: Likewise. + * sysdeps/unix/sysv/linux/futimesat.c: Likewise. + * sysdeps/unix/sysv/linux/fxstatat.c: Likewise. + * sysdeps/unix/sysv/linux/fxstatat64.c: Likewise. + * sysdeps/unix/sysv/linux/i386/fchownat.c: Likewise. + * sysdeps/unix/sysv/linux/i386/fxstatat.c: Likewise. + * sysdeps/unix/sysv/linux/linkat.c: Likewise. + * sysdeps/unix/sysv/linux/mkdirat.c: Likewise. + * sysdeps/unix/sysv/linux/openat.c: Likewise. + * sysdeps/unix/sysv/linux/powerpc/fchownat.c: Likewise. + * sysdeps/unix/sysv/linux/readlinkat.c: Likewise. + * sysdeps/unix/sysv/linux/renameat.c: Likewise. + * sysdeps/unix/sysv/linux/symlinkat.c: Likewise. + * sysdeps/unix/sysv/linux/unlinkat.c: Likewise. + * sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c: Likewise. + * sysdeps/unix/sysv/linux/xmknodat.c: Likewise. + [BZ #10643] * sysdeps/pthread/aio_misc.c (__aio_enqueue_request): If thread creation filed, remove the request from the 'requests' list and signal diff --git a/sysdeps/unix/sysv/linux/faccessat.c b/sysdeps/unix/sysv/linux/faccessat.c index 10b903d..c154deb 100644 --- a/sysdeps/unix/sysv/linux/faccessat.c +++ b/sysdeps/unix/sysv/linux/faccessat.c @@ -1,5 +1,5 @@ /* Test for access to file, relative to open directory. Linux version. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -72,6 +72,12 @@ faccessat (fd, file, mode, flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/fchmodat.c b/sysdeps/unix/sysv/linux/fchmodat.c index 8b42015..0516912 100644 --- a/sysdeps/unix/sysv/linux/fchmodat.c +++ b/sysdeps/unix/sysv/linux/fchmodat.c @@ -1,5 +1,5 @@ /* Change the protections of file relative to open directory. Linux version. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -71,6 +71,12 @@ fchmodat (fd, file, mode, flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/fchownat.c b/sysdeps/unix/sysv/linux/fchownat.c index 0f73177..db43755 100644 --- a/sysdeps/unix/sysv/linux/fchownat.c +++ b/sysdeps/unix/sysv/linux/fchownat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -66,6 +66,12 @@ fchownat (fd, file, owner, group, flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/futimesat.c b/sysdeps/unix/sysv/linux/futimesat.c index 7c96b78..bb83e74 100644 --- a/sysdeps/unix/sysv/linux/futimesat.c +++ b/sysdeps/unix/sysv/linux/futimesat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -76,6 +76,12 @@ futimesat (fd, file, tvp) else if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/fxstatat.c b/sysdeps/unix/sysv/linux/fxstatat.c index 1b9add4..dd5c9bc 100644 --- a/sysdeps/unix/sysv/linux/fxstatat.c +++ b/sysdeps/unix/sysv/linux/fxstatat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -85,6 +85,12 @@ __fxstatat (int vers, int fd, const char *file, struct stat *st, int flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/fxstatat64.c b/sysdeps/unix/sysv/linux/fxstatat64.c index cb932b8..442e4ca 100644 --- a/sysdeps/unix/sysv/linux/fxstatat64.c +++ b/sysdeps/unix/sysv/linux/fxstatat64.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005,2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -90,6 +90,12 @@ __fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/i386/fchownat.c b/sysdeps/unix/sysv/linux/i386/fchownat.c index 34acf10..1b02fde 100644 --- a/sysdeps/unix/sysv/linux/i386/fchownat.c +++ b/sysdeps/unix/sysv/linux/i386/fchownat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -63,6 +63,12 @@ fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/i386/fxstatat.c b/sysdeps/unix/sysv/linux/i386/fxstatat.c index 94f6e81..3775793 100644 --- a/sysdeps/unix/sysv/linux/i386/fxstatat.c +++ b/sysdeps/unix/sysv/linux/i386/fxstatat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -86,6 +86,12 @@ __fxstatat (int vers, int fd, const char *file, struct stat *st, int flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/linkat.c b/sysdeps/unix/sysv/linux/linkat.c index cfd0e18..b2b7b03 100644 --- a/sysdeps/unix/sysv/linux/linkat.c +++ b/sysdeps/unix/sysv/linux/linkat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -66,6 +66,12 @@ linkat (fromfd, from, tofd, to, flags) if (fromfd != AT_FDCWD && from[0] != '/') { size_t filelen = strlen (from); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ - the file descriptor number diff --git a/sysdeps/unix/sysv/linux/mkdirat.c b/sysdeps/unix/sysv/linux/mkdirat.c index 3c19008..aa89d08 100644 --- a/sysdeps/unix/sysv/linux/mkdirat.c +++ b/sysdeps/unix/sysv/linux/mkdirat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -57,6 +57,12 @@ mkdirat (fd, file, mode) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/openat.c b/sysdeps/unix/sysv/linux/openat.c index 45b566f..7916c71 100644 --- a/sysdeps/unix/sysv/linux/openat.c +++ b/sysdeps/unix/sysv/linux/openat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -110,6 +110,12 @@ OPENAT_NOT_CANCEL (fd, file, oflag, mode) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/powerpc/fchownat.c b/sysdeps/unix/sysv/linux/powerpc/fchownat.c index 67c5706..46f6d97 100644 --- a/sysdeps/unix/sysv/linux/powerpc/fchownat.c +++ b/sysdeps/unix/sysv/linux/powerpc/fchownat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -66,6 +66,12 @@ fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/readlinkat.c b/sysdeps/unix/sysv/linux/readlinkat.c index 1361596..1e9a9b6 100644 --- a/sysdeps/unix/sysv/linux/readlinkat.c +++ b/sysdeps/unix/sysv/linux/readlinkat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -59,6 +59,12 @@ readlinkat (fd, path, buf, len) if (fd != AT_FDCWD && path[0] != '/') { size_t pathlen = strlen (path); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/renameat.c b/sysdeps/unix/sysv/linux/renameat.c index 86bb75a..160bdc4 100644 --- a/sysdeps/unix/sysv/linux/renameat.c +++ b/sysdeps/unix/sysv/linux/renameat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -135,6 +135,12 @@ renameat (oldfd, old, newfd, new) if (oldfd != AT_FDCWD && old[0] != '/') { size_t filelen = strlen (old); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ - the file descriptor number @@ -154,6 +160,12 @@ renameat (oldfd, old, newfd, new) if (newfd != AT_FDCWD && new[0] != '/') { size_t filelen = strlen (new); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ - the file descriptor number diff --git a/sysdeps/unix/sysv/linux/symlinkat.c b/sysdeps/unix/sysv/linux/symlinkat.c index 4cfc924..d270477 100644 --- a/sysdeps/unix/sysv/linux/symlinkat.c +++ b/sysdeps/unix/sysv/linux/symlinkat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -57,6 +57,12 @@ symlinkat (from, tofd, to) if (tofd != AT_FDCWD && to[0] != '/') { size_t tolen = strlen (to); + if (__builtin_expect (tolen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/unlinkat.c b/sysdeps/unix/sysv/linux/unlinkat.c index 0a07a8a..bb5f898 100644 --- a/sysdeps/unix/sysv/linux/unlinkat.c +++ b/sysdeps/unix/sysv/linux/unlinkat.c @@ -1,5 +1,5 @@ /* unlinkat -- Remove a link by relative name. - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -64,6 +64,12 @@ unlinkat (fd, file, flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c b/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c index 8b1c932..cc41fde 100644 --- a/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c +++ b/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -72,6 +72,12 @@ __fxstatat (int vers, int fd, const char *file, struct stat *st, int flag) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ diff --git a/sysdeps/unix/sysv/linux/xmknodat.c b/sysdeps/unix/sysv/linux/xmknodat.c index ef27b68..177b3db 100644 --- a/sysdeps/unix/sysv/linux/xmknodat.c +++ b/sysdeps/unix/sysv/linux/xmknodat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -72,6 +72,12 @@ __xmknodat (int vers, int fd, const char *file, mode_t mode, dev_t *dev) if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); + if (__builtin_expect (filelen == 0, 0)) + { + __set_errno (ENOENT); + return -1; + } + static const char procfd[] = "/proc/self/fd/%d/%s"; /* Buffer for the path name we are going to use. It consists of - the string /proc/self/fd/ -- 2.7.4