From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15680 invoked by alias); 18 Nov 2005 21:10:10 -0000 Received: (qmail 15664 invoked by uid 22791); 18 Nov 2005 21:10:10 -0000 Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Fri, 18 Nov 2005 21:10:10 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id jAIL9weB010521; Fri, 18 Nov 2005 22:09:58 +0100 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id jAIL9wkv010520; Fri, 18 Nov 2005 22:09:58 +0100 Date: Fri, 18 Nov 2005 21:10:00 -0000 From: Jakub Jelinek To: Ulrich Drepper , Roland McGrath Cc: Glibc hackers Subject: [PATCH] Fix futimesat with NULL second argument Message-ID: <20051118210957.GO16723@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2005-11/txt/msg00015.txt.bz2 Hi! According to http://docs.sun.com/app/docs/doc/816-5167/6mbb2jam2?a=view futimesat (fd, NULL, tvp) is supposed to set times on the file referenced by fd. touch from coreutils uses this, so with current CVS glibc crashes (see https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=173581). It is unclear what happens with futimesat (AT_FDCWD, NULL, tvp) though, my patch will just fail, other variant would be set times on current working directory. Also, in generic futimesat.c, the documentation above says that for absolute paths fd argument is ignored. Therefore we shouldn't IMHO verify that FD is non-negative or AT_FDCWD in that case. 2005-11-18 Jakub Jelinek * sysdeps/unix/sysv/linux/futimesat.c (futimesat): If FILE is NULL, set access and modification times of the file referenced by FD. * sysdeps/generic/futimesat.c (futimesat): Don't return EINVAL if FILE is NULL. Don't check FD if FILE is absolute path. --- libc/sysdeps/unix/sysv/linux/futimesat.c.jj 2005-11-18 20:48:37.000000000 +0100 +++ libc/sysdeps/unix/sysv/linux/futimesat.c 2005-11-18 21:59:12.000000000 +0100 @@ -37,7 +37,22 @@ futimesat (fd, file, tvp) { char *buf = NULL; - if (fd != AT_FDCWD && file[0] != '/') + if (file == NULL) + { + static const char procfd[] = "/proc/self/fd/%d"; + /* Buffer for the path name we are going to use. It consists of + - the string /proc/self/fd/ + - the file descriptor number. + The final NUL is included in the sizeof. A bit of overhead + due to the format elements compensates for possible negative + numbers. */ + size_t buflen = sizeof (procfd) + sizeof (int) * 3; + buf = alloca (buflen); + + __snprintf (buf, buflen, procfd, fd); + file = buf; + } + else if (fd != AT_FDCWD && file[0] != '/') { size_t filelen = strlen (file); static const char procfd[] = "/proc/self/fd/%d/%s"; --- libc/sysdeps/generic/futimesat.c.jj 2005-11-11 20:02:44.000000000 +0100 +++ libc/sysdeps/generic/futimesat.c 2005-11-18 21:54:36.000000000 +0100 @@ -30,18 +30,14 @@ futimesat (fd, file, tvp) const char *file; const struct timeval tvp[2]; { - if (fd < 0 && fd != AT_FDCWD) + if (fd < 0 + && (file == NULL + || (fd != AT_FDCWD && file[0] != '/'))) { __set_errno (EBADF); return -1; } - if (file == NULL) - { - __set_errno (EINVAL); - return -1; - } - __set_errno (ENOSYS); return -1; } Jakub