diff options
author | Georg Brandl <georg@python.org> | 2006-10-12 11:27:59 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-10-12 11:27:59 (GMT) |
commit | 2c1375c8db6d62128f594aec3820292576daff8b (patch) | |
tree | d9247df3a02819561d645310e7a153368689ddd9 /Objects | |
parent | 7d74a0e2874632393906becc0d8db20412431d72 (diff) | |
download | cpython-2c1375c8db6d62128f594aec3820292576daff8b.zip cpython-2c1375c8db6d62128f594aec3820292576daff8b.tar.gz cpython-2c1375c8db6d62128f594aec3820292576daff8b.tar.bz2 |
Bug #1545497: when given an explicit base, int() did ignore NULs
embedded in the string to convert.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/intobject.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index a4d50be..8aa8d0b 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -987,8 +987,25 @@ int_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return PyInt_FromLong(0L); if (base == -909) return PyNumber_Int(x); - if (PyString_Check(x)) - return PyInt_FromString(PyString_AS_STRING(x), NULL, base); + if (PyString_Check(x)) { + /* Since PyInt_FromString doesn't have a length parameter, + * check here for possible NULs in the string. */ + char *string = PyString_AS_STRING(x); + if (strlen(string) != PyString_Size(x)) { + /* create a repr() of the input string, + * just like PyInt_FromString does */ + PyObject *srepr; + srepr = PyObject_Repr(x); + if (srepr == NULL) + return NULL; + PyErr_Format(PyExc_ValueError, + "invalid literal for int() with base %d: %s", + base, PyString_AS_STRING(srepr)); + Py_DECREF(srepr); + return NULL; + } + return PyInt_FromString(string, NULL, base); + } #ifdef Py_USING_UNICODE if (PyUnicode_Check(x)) return PyInt_FromUnicode(PyUnicode_AS_UNICODE(x), |