public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>, Roland McGrath <roland@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix futimesat with NULL second argument
Date: Fri, 18 Nov 2005 21:10:00 -0000	[thread overview]
Message-ID: <20051118210957.GO16723@sunsite.mff.cuni.cz> (raw)

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

             reply	other threads:[~2005-11-18 21:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-18 21:10 Jakub Jelinek [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051118210957.GO16723@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    --cc=roland@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).