diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2020-03-12 10:15:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-12 10:15:17 +0200 |
| commit | 6f4e7fcfca6923d0422b20fc8702240bd4e56ebd (patch) | |
| tree | 2a4b339c9e394bbaf2b1e27a5707ac77d59c7946 /Objects | |
| parent | 500999fbdfdea8c86ed84221b5cad551daa8cf9f (diff) | |
| download | cpython-git-6f4e7fcfca6923d0422b20fc8702240bd4e56ebd.tar.gz | |
[3.7] bpo-38643: Raise SystemError instead of crashing when PyNumber_ToBase is called with invalid base. (GH-18863). (GH-18955)
(cherry picked from commit e5ccc94bbb153431698b2391df625e8d47a93276)
Diffstat (limited to 'Objects')
| -rw-r--r-- | Objects/abstract.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index e6831feb82..4acb87266b 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1480,18 +1480,15 @@ PyNumber_Float(PyObject *o) PyObject * PyNumber_ToBase(PyObject *n, int base) { - PyObject *res = NULL; + if (!(base == 2 || base == 8 || base == 10 || base == 16)) { + PyErr_SetString(PyExc_SystemError, + "PyNumber_ToBase: base must be 2, 8, 10 or 16"); + return NULL; + } PyObject *index = PyNumber_Index(n); - if (!index) return NULL; - if (PyLong_Check(index)) - res = _PyLong_Format(index, base); - else - /* It should not be possible to get here, as - PyNumber_Index already has a check for the same - condition */ - PyErr_SetString(PyExc_ValueError, "PyNumber_ToBase: index not int"); + PyObject *res = _PyLong_Format(index, base); Py_DECREF(index); return res; } |
