This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] times fixes


Hi!

INTERNAL_SYSCALL_ERRNO returns positive errno numbers, not negative, so
the verification code would never trigger.
Also, if times() syscall returns -1, it is a valid value, but for times()
userland function (clock_t) -1 says an error happened and errno should
contain the error value.

2008-04-22  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/times.c (__times): Fix check for EFAULT.
	Avoid returning -1, return 0 instead.

--- libc/sysdeps/unix/sysv/linux/times.c.jj	2008-04-19 18:43:26.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/times.c	2008-04-22 09:19:26.000000000 +0200
@@ -27,7 +27,7 @@ __times (struct tms *buf)
   INTERNAL_SYSCALL_DECL (err);
   clock_t ret = INTERNAL_SYSCALL (times, err, 1, buf);
   if (INTERNAL_SYSCALL_ERROR_P (ret, err)
-      && __builtin_expect (INTERNAL_SYSCALL_ERRNO (ret, err) == -EFAULT, 0))
+      && __builtin_expect (INTERNAL_SYSCALL_ERRNO (ret, err) == EFAULT, 0))
     {
       /* This might be an error or not.  For architectures which have
 	 no separate return value and error indicators we cannot
@@ -49,6 +49,11 @@ __times (struct tms *buf)
 	 return an EFAULT error.  Return the value given by the kernel.  */
     }
 
+  /* Return value (clock_t) -1 signals an error, but if there wasn't any,
+     return the following value.  */
+  if (ret == (clock_t) -1)
+    return (clock_t) 0;
+
   return ret;
 }
 weak_alias (__times, times)

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]