]> granicus.if.org Git - python/commitdiff
bpo-30237: Output error when ReadConsole is canceled by CancelSynchronousIo. (GH...
authorValeriyaSinevich <valeriya.sinevich@phystech.edu>
Thu, 19 Jul 2018 22:34:03 +0000 (15:34 -0700)
committerSteve Dower <steve.dower@microsoft.com>
Thu, 19 Jul 2018 22:34:03 +0000 (15:34 -0700)
Misc/NEWS.d/next/Windows/2018-06-25-09-33-48.bpo-30237.EybiZA.rst [new file with mode: 0644]
Modules/_io/winconsoleio.c
Parser/myreadline.c

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 (file)
index 0000000..18aac75
--- /dev/null
@@ -0,0 +1,2 @@
+Output error when ReadConsole is canceled by CancelSynchronousIo instead of
+crashing.
index 2bf48eb55532d81ad5a00c584643683dd7ef284c..f08406643f0323a53ae2e7dafb88f53956296081 100644 (file)
@@ -556,7 +556,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);
 
@@ -564,6 +565,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)
index 2aa3bef2b0bbf6ede7b1e2dbf422db9fab39cde2..edb291a6691a78fffed1f905de9092d558da58e0 100644 (file)
@@ -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;
@@ -121,6 +121,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();