From 68bb9a1418f15eede43242eb3619ee5e4d0a85cb Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Mon, 30 Apr 2007 16:04:57 +0000 Subject: When accessing the .value attribute of a c_wchar_p instance, and the instance does not point to a valid wchar_t zero-terminated string, raise a ValueError. c_char_p does this already. The ValueError message now contains the correct pointer address. Will backport to release25-maint. --- Modules/_ctypes/cfield.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index e7bf274..6b0a526 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1366,7 +1366,7 @@ z_get(void *ptr, unsigned size) if (IsBadStringPtrA(*(char **)ptr, -1)) { PyErr_Format(PyExc_ValueError, "invalid string pointer %p", - ptr); + *(char **)ptr); return NULL; } #endif @@ -1451,9 +1451,17 @@ Z_get(void *ptr, unsigned size) { wchar_t *p; p = *(wchar_t **)ptr; - if (p) + if (p) { +#if defined(MS_WIN32) && !defined(_WIN32_WCE) + if (IsBadStringPtrW(*(wchar_t **)ptr, -1)) { + PyErr_Format(PyExc_ValueError, + "invalid string pointer %p", + *(wchar_t **)ptr); + return NULL; + } +#endif return PyUnicode_FromWideChar(p, wcslen(p)); - else { + } else { Py_INCREF(Py_None); return Py_None; } -- cgit v0.12