]> granicus.if.org Git - python/commitdiff
Issue #9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 24 Jun 2013 21:13:24 +0000 (23:13 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 24 Jun 2013 21:13:24 +0000 (23:13 +0200)
Modules/_winapi.c

index 1074891ef11aa4ae4d826088b97f6960d3d43722..c34d2db2678c02c0af5e1e6c5b536fad3617e1f0 100644 (file)
@@ -62,6 +62,8 @@
 
 #define T_HANDLE T_POINTER
 
+#define DWORD_MAX 4294967295U
+
 /* Grab CancelIoEx dynamically from kernel32 */
 static int has_CancelIoEx = -1;
 static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED);
@@ -1142,7 +1144,7 @@ winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds)
     HANDLE handle;
     Py_buffer _buf, *buf;
     PyObject *bufobj;
-    DWORD written;
+    DWORD len, written;
     BOOL ret;
     int use_overlapped = 0;
     DWORD err;
@@ -1170,7 +1172,8 @@ winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds)
     }
 
     Py_BEGIN_ALLOW_THREADS
-    ret = WriteFile(handle, buf->buf, buf->len, &written,
+    len = (DWORD)Py_MIN(buf->len, DWORD_MAX);
+    ret = WriteFile(handle, buf->buf, len, &written,
                     overlapped ? &overlapped->overlapped : NULL);
     Py_END_ALLOW_THREADS