aboutsummaryrefslogtreecommitdiffstats
path: root/src/w32.c
diff options
context:
space:
mode:
authorJason Rumney <[email protected]>2003-08-27 22:57:54 +0000
committerJason Rumney <[email protected]>2003-08-27 22:57:54 +0000
commitcb72110db2d80e522c199bde20d5c0857c0620fd (patch)
tree7bff5405848f05cddb6038e828ca3b2c66323319 /src/w32.c
parentd3703de36c308da1dea95bbd10505432b4e7950b (diff)
(sys_pipe): Protect against file descriptor overflow.
Diffstat (limited to 'src/w32.c')
-rw-r--r--src/w32.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/w32.c b/src/w32.c
index 744cc59313..f973999947 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -3450,11 +3450,22 @@ sys_pipe (int * phandles)
if (rc == 0)
{
- flags = FILE_PIPE | FILE_READ | FILE_BINARY;
- fd_info[phandles[0]].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;
+ flags = FILE_PIPE | FILE_WRITE | FILE_BINARY;
+ fd_info[phandles[1]].flags = flags;
+ }
}
return rc;