msys2-runtime icon indicating copy to clipboard operation
msys2-runtime copied to clipboard

Problem with infinite loop in console handling

Open cminyard opened this issue 3 years ago • 2 comments

In winsup/cygwin/fhandler_console.cc there is the following code:

             while (n < total_read)
                {
                  DWORD len;
                  WriteConsoleInputW (p->input_handle, input_rec + n,
                                      min (total_read - n, inrec_size1), &len);
                  n += len;
                }

I was working on a remote login program, and it turns out that if you create a pseudo console in a higher integrity process than the process using the console, WriteConsoleInput will not work (See https://learn.microsoft.com/en-us/answers/questions/1040676/createpseudoconsole-with-reduced-integrity-level.html for details on that)

If WriteConsoleInputW() fails the above code will go into an infinite loop.

I was able to fix my program with great pain and suffering, but things like the above should be written to avoid possible infinite loops. The lack of error checking in general doesn't seem good to me.

cminyard avatar Oct 11 '22 06:10 cminyard

Please provide a patch by way of a Pull Request.

dscho avatar Oct 18 '22 12:10 dscho

The code now lives in https://github.com/cygwin/cygwin/blob/main/winsup/cygwin/fhandler/console.cc there are three buggy loops like this, two for WriteConsoleInputW and one for ReadConsoleInputW.

lazka avatar Jan 27 '24 10:01 lazka