[Python-checkins] cpython (3.3): Issue #18556: Check the return value for PyUnicode_AsWideChar() in

brett.cannon python-checkins at python.org
Thu Jul 25 23:36:40 CEST 2013


http://hg.python.org/cpython/rev/78e8980ec9f7
changeset:   84827:78e8980ec9f7
branch:      3.3
parent:      84821:68fce7587f72
user:        Brett Cannon <brett at python.org>
date:        Thu Jul 25 17:34:00 2013 -0400
summary:
  Issue #18556: Check the return value for PyUnicode_AsWideChar() in
U_set() from ctypes.

CID #486657

files:
  Misc/NEWS                |  3 +++
  Modules/_ctypes/cfield.c |  6 +++++-
  2 files changed, 8 insertions(+), 1 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -52,6 +52,9 @@
 Library
 -------
 
+- Issue #18556: Check the return value of a PyUnicode_AsWideChar() call in
+  ctypes' U_set().
+
 - Issue #18549: Eliminate dead code in socket_ntohl()
 
 - Issue #18514: Fix unreachable Py_DECREF() call in PyCData_FromBaseObj()
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1260,7 +1260,11 @@
     } else if (size < length-1)
         /* copy terminating NUL character if there is space */
         size += 1;
-    PyUnicode_AsWideChar(value, (wchar_t *)ptr, size);
+
+    if (PyUnicode_AsWideChar(value, (wchar_t *)ptr, size) == -1) {
+        return NULL;
+    }
+
     return value;
 }
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list