[Python-checkins] cpython: Issue #18408: Fix call_exc_trace(): if the traceback is NULL, use None when

victor.stinner python-checkins at python.org
Wed Jul 10 14:04:13 CEST 2013


http://hg.python.org/cpython/rev/4f730c045f5f
changeset:   84529:4f730c045f5f
user:        Victor Stinner <vstinner at wyplay.com>
date:        Wed Jul 10 13:57:55 2013 +0200
summary:
  Issue #18408: Fix call_exc_trace(): if the traceback is NULL, use None when
building the tuple (type, value, traceback) passed to the callback.

PyTuple_Pack() does crash if an argument is NULL.

files:
  Python/ceval.c |  11 ++++++++---
  1 files changed, 8 insertions(+), 3 deletions(-)


diff --git a/Python/ceval.c b/Python/ceval.c
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3817,7 +3817,7 @@
 static void
 call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f)
 {
-    PyObject *type, *value, *traceback, *arg;
+    PyObject *type, *value, *traceback, *orig_traceback, *arg;
     int err;
     PyErr_Fetch(&type, &value, &traceback);
     if (value == NULL) {
@@ -3825,6 +3825,11 @@
         Py_INCREF(value);
     }
     PyErr_NormalizeException(&type, &value, &traceback);
+    orig_traceback = traceback;
+    if (traceback == NULL) {
+        Py_INCREF(Py_None);
+        traceback = Py_None;
+    }
     arg = PyTuple_Pack(3, type, value, traceback);
     if (arg == NULL) {
         PyErr_Restore(type, value, traceback);
@@ -3833,11 +3838,11 @@
     err = call_trace(func, self, f, PyTrace_EXCEPTION, arg);
     Py_DECREF(arg);
     if (err == 0)
-        PyErr_Restore(type, value, traceback);
+        PyErr_Restore(type, value, orig_traceback);
     else {
         Py_XDECREF(type);
         Py_XDECREF(value);
-        Py_XDECREF(traceback);
+        Py_XDECREF(orig_traceback);
     }
 }
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list