summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-10-05 18:57:54 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2006-10-05 18:57:54 (GMT)
commite67841f113f40327561641ca33945490ceeb3a8a (patch)
tree71cf4e84ddcb39c9cc40d835967f60db30d31aa7 /Python/pythonrun.c
parentda604c19923ef1fd365a0ace5bb8c6e0bbe763ce (diff)
downloadcpython-e67841f113f40327561641ca33945490ceeb3a8a.zip
cpython-e67841f113f40327561641ca33945490ceeb3a8a.tar.gz
cpython-e67841f113f40327561641ca33945490ceeb3a8a.tar.bz2
[Backport r50685 | neal.norwitz]
Reported by Klocwork #151. v2 can be NULL if exception2 is NULL. I don't think that condition can happen, but I'm not sure it can't either. Now the code will protect against either being NULL.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 6d6d1d5..e8392ee 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1080,6 +1080,17 @@ PyErr_PrintEx(int set_sys_last_vars)
}
PyErr_Fetch(&exception2, &v2, &tb2);
PyErr_NormalizeException(&exception2, &v2, &tb2);
+ /* It should not be possible for exception2 or v2
+ to be NULL. However PyErr_Display() can't
+ tolerate NULLs, so just be safe. */
+ if (exception2 == NULL) {
+ exception2 = Py_None;
+ Py_INCREF(exception2);
+ }
+ if (v2 == NULL) {
+ v2 = Py_None;
+ Py_INCREF(v2);
+ }
if (Py_FlushLine())
PyErr_Clear();
fflush(stdout);
@@ -1087,8 +1098,8 @@ PyErr_PrintEx(int set_sys_last_vars)
PyErr_Display(exception2, v2, tb2);
PySys_WriteStderr("\nOriginal exception was:\n");
PyErr_Display(exception, v, tb);
- Py_XDECREF(exception2);
- Py_XDECREF(v2);
+ Py_DECREF(exception2);
+ Py_DECREF(v2);
Py_XDECREF(tb2);
}
Py_XDECREF(result);