summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-07-17 00:59:04 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-07-17 00:59:04 (GMT)
commita5e4f22bfb552c2d7a384b651f04666a2a6b87d1 (patch)
tree8b602028cabbd2459157bd20c2d8c7083b132cc9
parent04e39ec81592915803bc253a6567153d18a2e71a (diff)
downloadcpython-a5e4f22bfb552c2d7a384b651f04666a2a6b87d1.zip
cpython-a5e4f22bfb552c2d7a384b651f04666a2a6b87d1.tar.gz
cpython-a5e4f22bfb552c2d7a384b651f04666a2a6b87d1.tar.bz2
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.
-rw-r--r--Python/pythonrun.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 7e5c696..95a3372 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1064,6 +1064,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);
@@ -1071,8 +1082,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);