diff options
author | Victor Stinner <vstinner@python.org> | 2023-10-20 18:03:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-20 18:03:11 (GMT) |
commit | f1e751e933aa8c39c0e9cfa4cdc3f8f9f0538202 (patch) | |
tree | 78e958a08e7f3e7448f110bc8755b2e4343acec1 /Objects | |
parent | d8f32be5b6a736dc2fc9dca3f1bf176c82fc9b44 (diff) | |
download | cpython-f1e751e933aa8c39c0e9cfa4cdc3f8f9f0538202.zip cpython-f1e751e933aa8c39c0e9cfa4cdc3f8f9f0538202.tar.gz cpython-f1e751e933aa8c39c0e9cfa4cdc3f8f9f0538202.tar.bz2 |
gh-111089: PyUnicode_AsUTF8AndSize() sets size on error (#111106)
On error, PyUnicode_AsUTF8AndSize() now sets the size argument to -1,
to avoid undefined value.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 07d1b6e..80b1956 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3820,17 +3820,24 @@ PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize) { if (!PyUnicode_Check(unicode)) { PyErr_BadArgument(); + if (psize) { + *psize = -1; + } return NULL; } if (PyUnicode_UTF8(unicode) == NULL) { if (unicode_fill_utf8(unicode) == -1) { + if (psize) { + *psize = -1; + } return NULL; } } - if (psize) + if (psize) { *psize = PyUnicode_UTF8_LENGTH(unicode); + } return PyUnicode_UTF8(unicode); } |