From: Victor Stinner Date: Mon, 8 Jul 2013 20:17:52 +0000 (+0200) Subject: Issue #18408: PyObject_GC_NewVar() now raises SystemError exception if nitems X-Git-Tag: v3.4.0a1~288 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d1866c78a4caf9825a0ce90863c19f65279da86;p=python Issue #18408: PyObject_GC_NewVar() now raises SystemError exception if nitems is negative --- diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 51c80b236e..d96d2c7b68 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -1689,8 +1689,15 @@ _PyObject_GC_New(PyTypeObject *tp) PyVarObject * _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems) { - const size_t size = _PyObject_VAR_SIZE(tp, nitems); - PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(size); + size_t size; + PyVarObject *op; + + if (nitems < 0) { + PyErr_BadInternalCall(); + return NULL; + } + size = _PyObject_VAR_SIZE(tp, nitems); + op = (PyVarObject *) _PyObject_GC_Malloc(size); if (op != NULL) op = PyObject_INIT_VAR(op, tp, nitems); return op;