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