public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] fhandler_pipe: add sanity limit to handle loops
@ 2021-12-23 23:10 Jeremy Drake
  2021-12-24  0:06 ` Ken Brown
  0 siblings, 1 reply; 35+ messages in thread
From: Jeremy Drake @ 2021-12-23 23:10 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 1343 bytes --]

Attempt to avoid an exception I caught once in gdb, trying to debug
msys2/MSYS2-packages#2752.  Unfortunately I haven't been able to catch it
in the act again since, but with this change running on Windows on ARM64
has been more reliable than it had been.

---
 winsup/cygwin/fhandler_pipe.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler_pipe.cc
b/winsup/cygwin/fhandler_pipe.cc
index ba6b70f55..48713a38d 100644
--- a/winsup/cygwin/fhandler_pipe.cc
+++ b/winsup/cygwin/fhandler_pipe.cc
@@ -1239,7 +1239,7 @@ fhandler_pipe::get_query_hdl_per_process (WCHAR *name,
       if (!NT_SUCCESS (status))
        goto close_proc;

-      for (ULONG j = 0; j < phi->NumberOfHandles; j++)
+      for (ULONG j = 0; j < min(phi->NumberOfHandles, n_handle); j++)
        {
          /* Check for the peculiarity of cygwin read pipe */
          const ULONG access = FILE_READ_DATA | FILE_READ_EA
@@ -1309,7 +1309,7 @@ fhandler_pipe::get_query_hdl_per_system (WCHAR *name,
   if (!NT_SUCCESS (status))
     return NULL;

-  for (LONG i = (LONG) shi->NumberOfHandles - 1; i >= 0; i--)
+  for (LONG i = (LONG) min(shi->NumberOfHandles, n_handle) - 1; i >= 0; i--)
     {
       /* Check for the peculiarity of cygwin read pipe */
       const ULONG access = FILE_READ_DATA | FILE_READ_EA
--
2.34.1.windows.1


[-- Attachment #2: Type: text/plain, Size: 1408 bytes --]

From aba830150ebb1707c66acdad8254728c5f962705 Mon Sep 17 00:00:00 2001
From: Jeremy Drake <cygwin@jdrake.com>
Date: Thu, 23 Dec 2021 12:22:46 -0800
Subject: [PATCH] fhandler_pipe: add sanity limit to handle loops

Attempt to avoid an exception I caught once in gdb, trying to debug msys2/MSYS2-packages#2752
---
 winsup/cygwin/fhandler_pipe.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc
index ba6b70f55..48713a38d 100644
--- a/winsup/cygwin/fhandler_pipe.cc
+++ b/winsup/cygwin/fhandler_pipe.cc
@@ -1239,7 +1239,7 @@ fhandler_pipe::get_query_hdl_per_process (WCHAR *name,
       if (!NT_SUCCESS (status))
 	goto close_proc;
 
-      for (ULONG j = 0; j < phi->NumberOfHandles; j++)
+      for (ULONG j = 0; j < min(phi->NumberOfHandles, n_handle); j++)
 	{
 	  /* Check for the peculiarity of cygwin read pipe */
 	  const ULONG access = FILE_READ_DATA | FILE_READ_EA
@@ -1309,7 +1309,7 @@ fhandler_pipe::get_query_hdl_per_system (WCHAR *name,
   if (!NT_SUCCESS (status))
     return NULL;
 
-  for (LONG i = (LONG) shi->NumberOfHandles - 1; i >= 0; i--)
+  for (LONG i = (LONG) min(shi->NumberOfHandles, n_handle) - 1; i >= 0; i--)
     {
       /* Check for the peculiarity of cygwin read pipe */
       const ULONG access = FILE_READ_DATA | FILE_READ_EA
-- 
2.34.1.windows.1


^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2021-12-30 15:44 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-23 23:10 [PATCH] fhandler_pipe: add sanity limit to handle loops Jeremy Drake
2021-12-24  0:06 ` Ken Brown
2021-12-24  0:29   ` Jeremy Drake
2021-12-24 17:17     ` Ken Brown
2021-12-24 19:42       ` Jeremy Drake
2021-12-24 22:46         ` Ken Brown
2021-12-24 23:42           ` Jeremy Drake
2021-12-25  0:39           ` Jeremy Drake
2021-12-25  3:19             ` Takashi Yano
2021-12-25  3:47               ` Jeremy Drake
2021-12-25  4:12                 ` Takashi Yano
2021-12-25  5:40                   ` Jeremy Drake
2021-12-25 17:10                     ` Takashi Yano
2021-12-25 17:16                       ` Takashi Yano
2021-12-25 19:00                         ` Marco Atzeri
2021-12-25 19:20                       ` Jeremy Drake
2021-12-25 22:18                         ` Ken Brown
2021-12-25 23:00                         ` Jeremy Drake
2021-12-26  3:04                           ` Ken Brown
2021-12-26  4:56                             ` Jeremy Drake
2021-12-26 15:09                               ` Ken Brown
2021-12-26 16:04                                 ` Ken Brown
2021-12-26 16:24                                   ` Ken Brown
2021-12-26 21:35                                     ` Jeremy Drake
2021-12-26 22:18                                       ` Ken Brown
2021-12-26 22:43                                         ` Jeremy Drake
2021-12-26 23:12                                           ` Ken Brown
2021-12-26 23:23                                             ` Jeremy Drake
2021-12-27  2:42                                               ` Ken Brown
2021-12-27 21:12                                                 ` Jeremy Drake
2021-12-29 21:59                                             ` Ken Brown
2021-12-29 23:29                                               ` Jeremy Drake
2021-12-27 20:01     ` Jon Turney
2021-12-29  5:45       ` Jeremy Drake
2021-12-30 15:44         ` Jon Turney

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