Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e676297

Browse files
committed
Add check in long-to-int conversion for at least one digit.
1 parent 3b2b347 commit e676297

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Objects/longobject.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ PyLong_FromString(str, pend, base)
453453
int base;
454454
{
455455
int sign = 1;
456+
char *start;
456457
PyLongObject *z;
457458

458459
if ((base != 0 && base < 2) || base > 36) {
@@ -481,6 +482,7 @@ PyLong_FromString(str, pend, base)
481482
if (base == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
482483
str += 2;
483484
z = _PyLong_New(0);
485+
start = str;
484486
for ( ; z != NULL; ++str) {
485487
int k = -1;
486488
PyLongObject *temp;
@@ -497,6 +499,11 @@ PyLong_FromString(str, pend, base)
497499
Py_DECREF(z);
498500
z = temp;
499501
}
502+
if (str == start) {
503+
PyErr_SetString(PyExc_ValueError,
504+
"no digits in long int constant");
505+
return NULL;
506+
}
500507
if (sign < 0 && z != NULL && z->ob_size != 0)
501508
z->ob_size = -(z->ob_size);
502509
if (pend)

0 commit comments

Comments
 (0)