changeset 52353:373b8dc17c8b

(sys_pipe): Protect against file descriptor overflow.
author Jason Rumney <jasonr@gnu.org>
date Wed, 27 Aug 2003 22:57:54 +0000
parents f88c9c046632
children 5480186284b2
files src/w32.c
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/w32.c	Wed Aug 27 22:57:13 2003 +0000
+++ b/src/w32.c	Wed Aug 27 22:57:54 2003 +0000
@@ -3450,11 +3450,22 @@
 
   if (rc == 0)
     {
-      flags = FILE_PIPE | FILE_READ | FILE_BINARY;
-      fd_info[phandles[0]].flags = flags;
-
-      flags = FILE_PIPE | FILE_WRITE | FILE_BINARY;
-      fd_info[phandles[1]].flags = flags;
+      /* Protect against overflow, since Windows can open more handles than
+	 our fd_info array has room for.  */
+      if (phandles[0] >= MAXDESC || phandles[1] >= MAXDESC)
+	{
+	  _close (phandles[0]);
+	  _close (phandles[1]);
+	  rc = -1;
+	}
+      else
+	{
+	  flags = FILE_PIPE | FILE_READ | FILE_BINARY;
+	  fd_info[phandles[0]].flags = flags;
+
+	  flags = FILE_PIPE | FILE_WRITE | FILE_BINARY;
+	  fd_info[phandles[1]].flags = flags;
+	}
     }
 
   return rc;