public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix futimesat with NULL second argument
@ 2005-11-18 21:10 Jakub Jelinek
  2005-11-18 22:15 ` Jakub Jelinek
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jakub Jelinek @ 2005-11-18 21:10 UTC (permalink / raw)
  To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers

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  <jakub@redhat.com>

	* 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-11-24 18:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-18 21:10 [PATCH] Fix futimesat with NULL second argument Jakub Jelinek
2005-11-18 22:15 ` Jakub Jelinek
2005-11-19 17:19 ` Ulrich Drepper
2005-11-24 14:34 ` Andreas Schwab
2005-11-24 18:09   ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).