From e34fc700fcdf0587592f3ccfb2caf5d474ac952a Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Tue, 7 Mar 2006 12:08:42 +0000 Subject: [PATCH] Backport trunk's r42878 (neal.norwitz): Thanks to Coverity, these were all reported by their Prevent tool. and r42881 (thomas.wouters): Don't DECREF a borrowed reference. --- Lib/test/test_hotshot.py | 13 +++++++++++++ Modules/_hotshot.c | 6 ++++++ Modules/_sre.c | 2 +- Modules/audioop.c | 2 ++ Modules/regexmodule.c | 3 +-- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_hotshot.py b/Lib/test/test_hotshot.py index 721da57f1f73..4618439867d7 100644 --- a/Lib/test/test_hotshot.py +++ b/Lib/test/test_hotshot.py @@ -107,6 +107,19 @@ class HotShotTestCase(unittest.TestCase): profiler.close() os.unlink(self.logfn) + def test_bad_sys_path(self): + import sys + orig_path = sys.path + coverage = hotshot._hotshot.coverage + try: + # verify we require a list for sys.path + sys.path = 'abc' + self.assertRaises(RuntimeError, coverage, test_support.TESTFN) + # verify sys.path exists + del sys.path + self.assertRaises(RuntimeError, coverage, test_support.TESTFN) + finally: + sys.path = orig_path def test_main(): test_support.run_unittest(HotShotTestCase) diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c index b75b1a32fbd8..f3128e080deb 100644 --- a/Modules/_hotshot.c +++ b/Modules/_hotshot.c @@ -473,6 +473,8 @@ restart: } else if (!err) { result = PyTuple_New(4); + if (result == NULL) + return NULL; PyTuple_SET_ITEM(result, 0, PyInt_FromLong(what)); PyTuple_SET_ITEM(result, 2, PyInt_FromLong(fileno)); if (s1 == NULL) @@ -1486,6 +1488,10 @@ write_header(ProfilerObject *self) getcwd(cwdbuffer, sizeof cwdbuffer)); temp = PySys_GetObject("path"); + if (temp == NULL || !PyList_Check(temp)) { + PyErr_SetString(PyExc_RuntimeError, "sys.path must be a list"); + return -1; + } len = PyList_GET_SIZE(temp); for (i = 0; i < len; ++i) { PyObject *item = PyList_GET_ITEM(temp, i); diff --git a/Modules/_sre.c b/Modules/_sre.c index f97cb62761a5..327f54a7e9c6 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2980,7 +2980,7 @@ match_groupdict(MatchObject* self, PyObject* args, PyObject* kw) return result; failed: - Py_DECREF(keys); + Py_XDECREF(keys); Py_DECREF(result); return NULL; } diff --git a/Modules/audioop.c b/Modules/audioop.c index 52824b84b694..023d22b238e2 100644 --- a/Modules/audioop.c +++ b/Modules/audioop.c @@ -1013,6 +1013,8 @@ audioop_ratecv(PyObject *self, PyObject *args) while (d < 0) { if (len == 0) { samps = PyTuple_New(nchannels); + if (samps == NULL) + goto exit; for (chan = 0; chan < nchannels; chan++) PyTuple_SetItem(samps, chan, Py_BuildValue("(ii)", diff --git a/Modules/regexmodule.c b/Modules/regexmodule.c index 9f84032e4d46..f75e9b20ef7a 100644 --- a/Modules/regexmodule.c +++ b/Modules/regexmodule.c @@ -535,8 +535,7 @@ regex_symcomp(PyObject *self, PyObject *args) gdict = PyDict_New(); if (gdict == NULL || (npattern = symcomp(pattern, gdict)) == NULL) { - Py_DECREF(gdict); - Py_DECREF(pattern); + Py_XDECREF(gdict); return NULL; } retval = newregexobject(npattern, tran, pattern, gdict); -- 2.47.3