Skip to content

bpo-30237: Output error when ReadConsole is canceled by CancelSynchronousIo. #7911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 19, 2018
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Output error when ReadConsole is canceled by CancelSynchronousIo instead of
crashing.
6 changes: 5 additions & 1 deletion Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,18 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
Py_BEGIN_ALLOW_THREADS
DWORD off = 0;
while (off < maxlen) {
DWORD n, len = min(maxlen - off, BUFSIZ);
DWORD n = (DWORD)-1;
DWORD len = min(maxlen - off, BUFSIZ);
SetLastError(0);
BOOL res = ReadConsoleW(handle, &buf[off], len, &n, NULL);

if (!res) {
err = GetLastError();
break;
}
if (n == (DWORD)-1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) {
break;
}
if (n == 0) {
err = GetLastError();
if (err != ERROR_OPERATION_ABORTED)
Expand Down
5 changes: 4 additions & 1 deletion Parser/myreadline.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn)
char *buf = NULL;
int err = 0;

n_read = 0;
n_read = (DWORD)-1;
total_read = 0;
wbuf = wbuf_local;
wbuflen = sizeof(wbuf_local) / sizeof(wbuf_local[0]) - 1;
Expand All @@ -118,6 +118,9 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn)
err = GetLastError();
goto exit;
}
if (n_read == (DWORD)-1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) {
break;
}
if (n_read == 0) {
int s;
err = GetLastError();
Expand Down