Skip to content

Commit de7990b

Browse files
committed
SF bug #1238681: freed pointer is used in longobject.c:long_pow().
In addition, long_pow() skipped a necessary (albeit extremely unlikely to trigger) error check when converting an int modulus to long. Alas, I was unable to write a test case that crashed due to either cause. Bugfix candidate.
1 parent f5f32b4 commit de7990b

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ What's New in Python 2.5 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- SF bug #1238681: freed pointer is used in longobject.c:long_pow().
16+
1517
- SF bug #1229429: PyObject_CallMethod failed to decrement some
1618
reference counts in some error exit cases.
1719

Objects/longobject.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,8 +2360,11 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
23602360
c = (PyLongObject *)x;
23612361
Py_INCREF(x);
23622362
}
2363-
else if (PyInt_Check(x))
2363+
else if (PyInt_Check(x)) {
23642364
c = (PyLongObject *)PyLong_FromLong(PyInt_AS_LONG(x));
2365+
if (c == NULL)
2366+
goto Error;
2367+
}
23652368
else if (x == Py_None)
23662369
c = NULL;
23672370
else {
@@ -2511,14 +2514,14 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
25112514
}
25122515
/* fall through */
25132516
Done:
2514-
Py_XDECREF(a);
2515-
Py_XDECREF(b);
2516-
Py_XDECREF(c);
2517-
Py_XDECREF(temp);
25182517
if (b->ob_size > FIVEARY_CUTOFF) {
25192518
for (i = 0; i < 32; ++i)
25202519
Py_XDECREF(table[i]);
25212520
}
2521+
Py_DECREF(a);
2522+
Py_DECREF(b);
2523+
Py_XDECREF(c);
2524+
Py_XDECREF(temp);
25222525
return (PyObject *)z;
25232526
}
25242527

0 commit comments

Comments
 (0)