gh-142029: Raise ValueError instead of crashing on empty name given to create_builtin() (#142033)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
dr-carlos 2025-12-10 17:01:57 +10:30 committed by GitHub
parent d716e3b2dd
commit 70671267c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 0 deletions

View file

@ -4420,6 +4420,12 @@ _imp_create_builtin(PyObject *module, PyObject *spec)
return NULL;
}
if (PyUnicode_GetLength(name) == 0) {
PyErr_Format(PyExc_ValueError, "name must not be empty");
Py_DECREF(name);
return NULL;
}
PyObject *mod = create_builtin(tstate, name, spec, NULL);
Py_DECREF(name);
return mod;