Commit f234eb0b authored by Guido van Rossum's avatar Guido van Rossum

Add check in long-to-int conversion for at least one digit.

parent 54d951ce
...@@ -453,6 +453,7 @@ PyLong_FromString(str, pend, base) ...@@ -453,6 +453,7 @@ PyLong_FromString(str, pend, base)
int base; int base;
{ {
int sign = 1; int sign = 1;
char *start;
PyLongObject *z; PyLongObject *z;
if ((base != 0 && base < 2) || base > 36) { if ((base != 0 && base < 2) || base > 36) {
...@@ -481,6 +482,7 @@ PyLong_FromString(str, pend, base) ...@@ -481,6 +482,7 @@ PyLong_FromString(str, pend, base)
if (base == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) if (base == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
str += 2; str += 2;
z = _PyLong_New(0); z = _PyLong_New(0);
start = str;
for ( ; z != NULL; ++str) { for ( ; z != NULL; ++str) {
int k = -1; int k = -1;
PyLongObject *temp; PyLongObject *temp;
...@@ -497,6 +499,11 @@ PyLong_FromString(str, pend, base) ...@@ -497,6 +499,11 @@ PyLong_FromString(str, pend, base)
Py_DECREF(z); Py_DECREF(z);
z = temp; z = temp;
} }
if (str == start) {
PyErr_SetString(PyExc_ValueError,
"no digits in long int constant");
return NULL;
}
if (sign < 0 && z != NULL && z->ob_size != 0) if (sign < 0 && z != NULL && z->ob_size != 0)
z->ob_size = -(z->ob_size); z->ob_size = -(z->ob_size);
if (pend) if (pend)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment