mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Check for PyUnicode_AS_UNICODE() failure
This commit is contained in:
parent
53b33e767d
commit
3335447646
4 changed files with 38 additions and 7 deletions
|
@ -1472,12 +1472,15 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
|
|||
/* create a BSTR from value */
|
||||
if (value) {
|
||||
Py_ssize_t size = PyUnicode_GET_SIZE(value);
|
||||
wchar_t* wvalue;
|
||||
if ((unsigned) size != size) {
|
||||
PyErr_SetString(PyExc_ValueError, "String too long for BSTR");
|
||||
return NULL;
|
||||
}
|
||||
bstr = SysAllocStringLen(PyUnicode_AS_UNICODE(value),
|
||||
(unsigned)size);
|
||||
wvalue = PyUnicode_AsUnicode(value);
|
||||
if (wvalue == NULL)
|
||||
return NULL;
|
||||
bstr = SysAllocStringLen(wvalue, (unsigned)size);
|
||||
Py_DECREF(value);
|
||||
} else
|
||||
bstr = NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue