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

Skip to content

Commit ff369a5

Browse files
committed
Fix possible NULL pointer dereferences in testcapi module
CID 1058280 CID 1058282 CID 1058284
1 parent a956e64 commit ff369a5

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Modules/_testcapimodule.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ test_dict_inner(int count)
120120

121121
for (i = 0; i < count; i++) {
122122
v = PyLong_FromLong(i);
123+
if (v == NULL) {
124+
Py_DECREF(v);
125+
return -1;
126+
}
123127
if (PyDict_SetItem(dict, v, v) < 0) {
124128
Py_DECREF(v);
125129
return -1;
@@ -1642,6 +1646,8 @@ test_long_numbits(PyObject *self)
16421646

16431647
for (i = 0; i < Py_ARRAY_LENGTH(testcases); ++i) {
16441648
PyObject *plong = PyLong_FromLong(testcases[i].input);
1649+
if (plong == NULL)
1650+
return NULL;
16451651
size_t nbits = _PyLong_NumBits(plong);
16461652
int sign = _PyLong_Sign(plong);
16471653

@@ -2234,7 +2240,7 @@ profile_int(PyObject *self, PyObject* args)
22342240
gettimeofday(&start, NULL);
22352241
for(i=0; i < 10000000; i++) {
22362242
result = PyNumber_Add(op1, op1);
2237-
Py_DECREF(result);
2243+
Py_XDECREF(result);
22382244
}
22392245
gettimeofday(&stop, NULL);
22402246
Py_DECREF(op1);

0 commit comments

Comments
 (0)