[PATCH v2 0/1] MR6605: cmd: Call ReadConsoleW() only with standard input handles.
-- v2: cmd: Call ReadConsoleW() with standard input handles only. https://gitlab.winehq.org/wine/wine/-/merge_requests/6605
From: Hans Leidekker <hans(a)codeweavers.com> --- programs/cmd/batch.c | 20 ++++++++++---------- programs/cmd/wcmdmain.c | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c index 25281df15f0..c2f74a33415 100644 --- a/programs/cmd/batch.c +++ b/programs/cmd/batch.c @@ -222,7 +222,16 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h) /* We can't use the native f* functions because of the filename syntax differences between DOS and Unix. Also need to lose the LF (or CRLF) from the line. */ - if (!ReadConsoleW(h, buf, noChars, &charsRead, NULL)) { + if (VerifyConsoleIoHandle(h) && ReadConsoleW(h, buf, noChars, &charsRead, NULL) && charsRead) { + if (!charsRead) return NULL; + + /* Find first EOL */ + for (i = 0; i < charsRead; i++) { + if (buf[i] == '\n' || buf[i] == '\r') + break; + } + } + else { LARGE_INTEGER filepos; char *bufA; UINT cp; @@ -254,15 +263,6 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h) i = MultiByteToWideChar(cp, 0, bufA, p - bufA, buf, noChars); free(bufA); } - else { - if (!charsRead) return NULL; - - /* Find first EOL */ - for (i = 0; i < charsRead; i++) { - if (buf[i] == '\n' || buf[i] == '\r') - break; - } - } /* Truncate at EOL (or end of buffer) */ if (i == noChars) diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 27c7def7900..0d3b201c095 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -222,7 +222,7 @@ BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars, LPDWO char *buffer; /* Try to read from console as Unicode */ - if (ReadConsoleW(hIn, intoBuf, maxChars, charsRead, NULL)) return TRUE; + if (VerifyConsoleIoHandle(hIn) && ReadConsoleW(hIn, intoBuf, maxChars, charsRead, NULL)) return TRUE; /* We assume it's a file handle and read then convert from assumed OEM codepage */ if (!(buffer = get_file_buffer())) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/6605
v2: Use VerifyConsoleIoHandle(). -- https://gitlab.winehq.org/wine/wine/-/merge_requests/6605#note_83891
participants (2)
-
Hans Leidekker -
Hans Leidekker (@hans)