From cbfaeba4f77b98219579b7569604de29e57cc9b9 Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Wed, 6 Nov 2024 14:06:58 +0900 Subject: [PATCH] Cygwin: pipe: Fix incorrect write length in raw_write() If the write length is more than the pipe space in non-blocking mode, the write length is wrongly set to 65536. This causes access violation. This patch fixes that. Fixes: 7ed9adb356df ("Cygwin: pipe: Switch pipe mode to blocking mode by default") Signed-off-by: Takashi Yano --- winsup/cygwin/fhandler/pipe.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc index a2729a119..76af6bc05 100644 --- a/winsup/cygwin/fhandler/pipe.cc +++ b/winsup/cygwin/fhandler/pipe.cc @@ -532,10 +532,8 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len) } } - if (len <= (size_t) avail || pipe_buf_size == 0) + if (len <= (size_t) avail) chunk = len; - else if (is_nonblocking ()) - chunk = len = pipe_buf_size; else chunk = avail; @@ -555,7 +553,7 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len) ULONG len1; DWORD waitret = WAIT_OBJECT_0; - if (left > chunk) + if (left > chunk && !is_nonblocking ()) len1 = chunk; else len1 = (ULONG) left;