ce426f
commit 58a1335e76a553e1cf4edeebc27f16fc9b53d6e6
ce426f
Author: Petr Baudis <pasky@ucw.cz>
ce426f
Date:   Thu Mar 14 01:16:53 2013 +0100
ce426f
ce426f
    Fix __times() handling of EFAULT when buf is NULL
ce426f
ce426f
diff --git a/sysdeps/unix/sysv/linux/times.c b/sysdeps/unix/sysv/linux/times.c
ce426f
index f3b5f01..e59bb4e 100644
ce426f
--- a/sysdeps/unix/sysv/linux/times.c
ce426f
+++ b/sysdeps/unix/sysv/linux/times.c
ce426f
@@ -26,13 +26,14 @@ __times (struct tms *buf)
ce426f
   INTERNAL_SYSCALL_DECL (err);
ce426f
   clock_t ret = INTERNAL_SYSCALL (times, err, 1, buf);
ce426f
   if (INTERNAL_SYSCALL_ERROR_P (ret, err)
ce426f
-      && __builtin_expect (INTERNAL_SYSCALL_ERRNO (ret, err) == EFAULT, 0))
ce426f
+      && __builtin_expect (INTERNAL_SYSCALL_ERRNO (ret, err) == EFAULT, 0)
ce426f
+      && buf)
ce426f
     {
ce426f
       /* This might be an error or not.  For architectures which have
ce426f
 	 no separate return value and error indicators we cannot
ce426f
 	 distinguish a return value of -1 from an error.  Do it the
ce426f
-	 hard way.  We crash applications which pass in an invalid BUF
ce426f
-	 pointer.  */
ce426f
+	 hard way.  We crash applications which pass in an invalid
ce426f
+	 non-NULL BUF pointer.  Linux allows BUF to be NULL. */
ce426f
 #define touch(v) \
ce426f
       do {								      \
ce426f
 	clock_t temp = v;						      \
ce426f
@@ -44,7 +45,8 @@ __times (struct tms *buf)
ce426f
       touch (buf->tms_cutime);
ce426f
       touch (buf->tms_cstime);
ce426f
 
ce426f
-      /* If we come here the memory is valid and the kernel did not
ce426f
+      /* If we come here the memory is valid (or BUF is NULL, which is
ce426f
+       * a valid condition for the kernel syscall) and the kernel did not
ce426f
 	 return an EFAULT error.  Return the value given by the kernel.  */
ce426f
     }
ce426f