Cygwin: console: Fix new bugs in cons_master_thread().

- The previous commit for console introduced new bugs in error
  handling in cons_master_thread(). This patch fixes that.
This commit is contained in:
Takashi Yano 2022-07-03 10:38:13 +09:00
parent 15dd408118
commit 8489ba9996
1 changed files with 9 additions and 8 deletions

View File

@ -361,7 +361,8 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
{ {
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
total_read = 0; total_read = 0;
while (cygwait (p->input_handle, (DWORD) 0) == WAIT_OBJECT_0) while (cygwait (p->input_handle, (DWORD) 0) == WAIT_OBJECT_0
&& total_read < inrec_size)
{ {
DWORD len; DWORD len;
ReadConsoleInputW (p->input_handle, input_rec + total_read, ReadConsoleInputW (p->input_handle, input_rec + total_read,
@ -477,7 +478,8 @@ remove_record:
/* Try to fix */ /* Try to fix */
acquire_attach_mutex (mutex_timeout); acquire_attach_mutex (mutex_timeout);
n = 0; n = 0;
while (cygwait (p->input_handle, (DWORD) 0) == WAIT_OBJECT_0) while (cygwait (p->input_handle, (DWORD) 0) == WAIT_OBJECT_0
&& n < inrec_size)
{ {
DWORD len; DWORD len;
ReadConsoleInputW (p->input_handle, input_tmp + n, ReadConsoleInputW (p->input_handle, input_tmp + n,
@ -492,14 +494,13 @@ remove_record:
if (total_read + j - i >= n) if (total_read + j - i >= n)
{ /* Something is wrong. Giving up. */ { /* Something is wrong. Giving up. */
acquire_attach_mutex (mutex_timeout); acquire_attach_mutex (mutex_timeout);
WriteConsoleInputW (p->input_handle, input_tmp, n, &n); DWORD l = 0;
n = 0; while (l < n)
while (n < total_read)
{ {
DWORD len; DWORD len;
WriteConsoleInputW (p->input_handle, input_rec + n, WriteConsoleInputW (p->input_handle, input_tmp + l,
min (total_read - n, inrec_size1), &len); min (n - l, inrec_size1), &len);
n += len; l += len;
} }
release_attach_mutex (); release_attach_mutex ();
goto skip_writeback; goto skip_writeback;