mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string. Klocwork 308
This commit is contained in:
parent
3cb31ac704
commit
56423e5762
3 changed files with 14 additions and 1 deletions
|
@ -4225,12 +4225,15 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
|
|||
if (!result)
|
||||
return NULL;
|
||||
|
||||
buf = PyString_AsString(result);
|
||||
if (!buf)
|
||||
return NULL;
|
||||
|
||||
/* To modify the string in-place, there can only be one reference. */
|
||||
if (result->ob_refcnt != 1) {
|
||||
PyErr_BadInternalCall();
|
||||
return NULL;
|
||||
}
|
||||
buf = PyString_AsString(result);
|
||||
llen = PyString_Size(result);
|
||||
if (llen > PY_SSIZE_T_MAX) {
|
||||
PyErr_SetString(PyExc_ValueError, "string too large in _PyString_FormatLong");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue