Index: unix/tclUnixPipe.c ================================================================== --- unix/tclUnixPipe.c +++ unix/tclUnixPipe.c @@ -153,10 +153,21 @@ Tcl_DString ds; native = Tcl_UtfToExternalDString(NULL, fname, -1, &ds); fd = TclOSopen(native, mode, 0666); /* INTL: Native. */ Tcl_DStringFree(&ds); + + /* + * Ticket [c6897e6e6a]. + */ + + if (fd >= FD_SETSIZE) { + close(fd); + fd = -1; + errno = EMFILE; + } + if (fd != -1) { fcntl(fd, F_SETFD, FD_CLOEXEC); /* * If the file is being opened for writing, seek to the end so we can @@ -318,10 +329,20 @@ int pipeIds[2]; if (pipe(pipeIds) != 0) { return 0; } + + /* + * Ticket [c6897e6e6a]. + */ + + if (pipeIds[0] >= FD_SETSIZE || pipeIds[1] >= FD_SETSIZE) { + close(pipeIds[0]); + close(pipeIds[1]); + return 0; + } fcntl(pipeIds[0], F_SETFD, FD_CLOEXEC); fcntl(pipeIds[1], F_SETFD, FD_CLOEXEC); *readPipe = MakeFile(pipeIds[0]); @@ -894,13 +915,27 @@ Tcl_Interp *interp, /* Errors returned in result. */ Tcl_Channel *rchan, /* Returned read side. */ Tcl_Channel *wchan, /* Returned write side. */ int flags) /* Reserved for future use. */ { - int fileNums[2]; + int ret, fileNums[2]; + + ret = pipe(fileNums); + if (ret >= 0) { + + /* + * Ticket [c6897e6e6a]. + */ - if (pipe(fileNums) < 0) { + if (fileNums[0] >= FD_SETSIZE || fileNums[1] >= FD_SETSIZE) { + close(fileNums[0]); + close(fileNums[1]); + errno = EMFILE; + ret = -1; + } + } + if (ret < 0) { Tcl_SetObjResult(interp, Tcl_ObjPrintf("pipe creation failed: %s", Tcl_PosixError(interp))); return TCL_ERROR; }