summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2018-07-29 09:32:30 (GMT)
committerGitHub <noreply@github.com>2018-07-29 09:32:30 (GMT)
commit28bbbdabb1e3601047530febac1b05b7b89dc65e (patch)
tree63ff263f98affe4a3d0c40b3e072dc2fca4bf894
parent94972d50bda19000bce498bd2c5ace6be9bec711 (diff)
downloadcpython-28bbbdabb1e3601047530febac1b05b7b89dc65e.zip
cpython-28bbbdabb1e3601047530febac1b05b7b89dc65e.tar.gz
cpython-28bbbdabb1e3601047530febac1b05b7b89dc65e.tar.bz2
bpo-30237: Output error when ReadConsole is canceled by CancelSynchronousIo. (GH-7911)
Co-authored-by: ValeriyaSinevich <valeriya.sinevich@phystech.edu>
-rw-r--r--Misc/NEWS.d/next/Windows/2018-06-25-09-33-48.bpo-30237.EybiZA.rst2
-rw-r--r--Modules/_io/winconsoleio.c6
-rw-r--r--Parser/myreadline.c5
3 files changed, 11 insertions, 2 deletions
diff --git a/Misc/NEWS.d/next/Windows/2018-06-25-09-33-48.bpo-30237.EybiZA.rst b/Misc/NEWS.d/next/Windows/2018-06-25-09-33-48.bpo-30237.EybiZA.rst
new file mode 100644
index 0000000..18aac75
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2018-06-25-09-33-48.bpo-30237.EybiZA.rst
@@ -0,0 +1,2 @@
+Output error when ReadConsole is canceled by CancelSynchronousIo instead of
+crashing.
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index 0d1b092..979bcfc 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -573,7 +573,8 @@ 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);
@@ -581,6 +582,9 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
err = GetLastError();
break;
}
+ if (n == (DWORD)-1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) {
+ break;
+ }
if (n == 0) {
err = GetLastError();
if (err != ERROR_OPERATION_ABORTED)
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
index bb02631..476af71 100644
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -114,7 +114,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;
@@ -126,6 +126,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();