gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed (GH-146113)
The function can fail on a memory allocation failure.
Bug reported by devdanzin.
(cherry picked from commit
724c7c8146f44a7c737ec4588a1ee4b9db994f6f)
Co-authored-by: Victor Stinner <vstinner@python.org>
static int
_set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
{
- if (src == NULL)
+ if (src == NULL) {
*target = PyUnicode_DecodeASCII(dflt, strlen(dflt), NULL);
+ if (*target == NULL) {
+ return -1;
+ }
+ }
else {
if (src == Py_None)
*target = NULL;