public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] times fixes
@ 2008-04-22  7:26 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2008-04-22  7:26 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-04-22  7:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-22  7:26 [PATCH] times fixes Jakub Jelinek

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).