changeset 12580:3a190157862b

utimens (fdutimens): ignore a negative FD, per contract * lib/utimens.c (fdutimens) [HAVE_FUTIMENS]: Call futimens only when we have a valid file descriptor. Otherwise, using a brand new glibc (with just-patched futimens that now fails with EBADF) would cause this function to fail with ENOSYS. Reported by Guillaume Ayoub in http://bugs.debian.org/563726. See also http://bugzilla.redhat.com/552320. Signed-off-by: Eric Blake <ebb9@byu.net>
author Aurelien Jarno <aurelien@aurel32.net>
date Tue, 05 Jan 2010 20:27:12 -0700
parents 502ce3cd8cd5
children 25232b487199
files ChangeLog lib/utimens.c
diffstat 2 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-01-05  Aurelien Jarno  <aurelien@aurel32.net>  (tiny change)
+
+	utimens (fdutimens): ignore a negative FD, per contract
+	* lib/utimens.c (fdutimens) [HAVE_FUTIMENS]: Call futimens only
+	when we have a valid file descriptor.  Otherwise, using a brand
+	new glibc (with just-patched futimens that now fails with EBADF)
+	would cause this function to fail with ENOSYS.
+	Reported by Guillaume Ayoub in http://bugs.debian.org/563726.
+	See also http://bugzilla.redhat.com/552320.
+
 2010-01-05  Eric Blake  <ebb9@byu.net>
 
 	strcase: document what it provides
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -264,19 +264,20 @@
         }
 # endif /* HAVE_UTIMENSAT */
 # if HAVE_FUTIMENS
-      {
-        result = futimens (fd, ts);
+      if (0 <= fd)
+        {
+          result = futimens (fd, ts);
 #  ifdef __linux__
-        /* Work around the same bug as above.  */
-        if (0 < result)
-          errno = ENOSYS;
+          /* Work around the same bug as above.  */
+          if (0 < result)
+            errno = ENOSYS;
 #  endif /* __linux__ */
-        if (result == 0 || errno != ENOSYS)
-          {
-            utimensat_works_really = 1;
-            return result;
-          }
-      }
+          if (result == 0 || errno != ENOSYS)
+            {
+              utimensat_works_really = 1;
+              return result;
+            }
+        }
 # endif /* HAVE_FUTIMENS */
     }
   utimensat_works_really = -1;