about summary refs log tree commit diff
path: root/misc
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-05-16 09:35:51 -0400
committerUlrich Drepper <drepper@gmail.com>2011-05-16 09:35:51 -0400
commit68a3f91fcad464c4737c1eaed4ae0bf539801fb2 (patch)
tree759c77da645a8dae65ae83cbe97a792197c9fa8c /misc
parent15cc7dd182a6be79cbb01a5de4f13e958717bd69 (diff)
downloadglibc-68a3f91fcad464c4737c1eaed4ae0bf539801fb2.tar.gz
glibc-68a3f91fcad464c4737c1eaed4ae0bf539801fb2.tar.xz
glibc-68a3f91fcad464c4737c1eaed4ae0bf539801fb2.zip
Fix reporting of invalid timeouts in emulated pselect
Diffstat (limited to 'misc')
-rw-r--r--misc/pselect.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/misc/pselect.c b/misc/pselect.c
index 80cf8be4b3..e29d7b36ad 100644
--- a/misc/pselect.c
+++ b/misc/pselect.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1998,2001-2003,2006,2011 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -43,7 +43,17 @@ __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
      precision and therefore the `pselect` should be available.  But
      for now it is hardly found.  */
   if (timeout != NULL)
-    TIMESPEC_TO_TIMEVAL (&tval, timeout);
+    {
+      /* Catch bugs which would be hidden by the TIMESPEC_TO_TIMEVAL
+	 computations.  The division by 1000 truncates values.  */
+      if (__builtin_expect (timeout->tv_nsec < 0, 0))
+	{
+	  __set_errno (EINVAL);
+	  return -1;
+	}
+
+      TIMESPEC_TO_TIMEVAL (&tval, timeout);
+    }
 
   /* The setting and restoring of the signal mask and the select call
      should be an atomic operation.  This can't be done without kernel