From 72b97c86c6c1a1902d6dcda3da7c38db13585cdc Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 17 Jul 2023 14:17:13 +0100 Subject: win32: avoid crashing the console with poll(2) Commit 8e6991733 (ash: fix 'read' shell built-in (1)) introduced the use of poll(2) in the shell 'read' built-in. When the UTF8 code page is in use this results in the console crashing if a 3 or more byte UTF8 character is entered. The crash is caused by the use of PeekConsoleInputA() which, like ReadConsoleInputA(), is broken. It can be avoided by using PeekConsoleInputW() instead. The number of key events will differ but this doesn't matter in this case as poll(2) effectively runs in a busy loop with a 1ms sleep. --- win32/poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32/poll.c b/win32/poll.c index 4b825c5cc..b39732887 100644 --- a/win32/poll.c +++ b/win32/poll.c @@ -234,7 +234,7 @@ windows_compute_revents (HANDLE h, int *p_sought) return 0; irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD)); - bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail); + bRet = PeekConsoleInputW (h, irbuffer, nbuffer, &avail); if (!bRet || avail == 0) return POLLHUP; -- cgit v1.2.3-55-g6feb