Skip to content

Commit

Permalink
Thanks to Coverity, these were all reported by their Prevent tool.
Browse files Browse the repository at this point in the history
All of these (except _lsprof.c) should be backported.  Particularly
the hotshot change which validates sys.path.  Can someone backport?


git-svn-id: http://svn.python.org/projects/python/trunk@42878 6015fed2-1504-0410-9fe1-9d1591cc4771
  • Loading branch information
neal.norwitz committed Mar 7, 2006
1 parent 3ee9007 commit 4523966
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Lib/test/test_hotshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ def test_start_stop(self):
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)
Expand Down
6 changes: 6 additions & 0 deletions Modules/_hotshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ logreader_tp_iternext(LogReaderObject *self)
}
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)
Expand Down Expand Up @@ -1455,6 +1457,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);
Expand Down
2 changes: 2 additions & 0 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ init_lsprof(void)
{
PyObject *module, *d;
module = Py_InitModule3("_lsprof", moduleMethods, "Fast profiler");
if (module == NULL)
return;
d = PyModule_GetDict(module);
if (PyType_Ready(&PyProfiler_Type) < 0)
return;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -2983,7 +2983,7 @@ match_groupdict(MatchObject* self, PyObject* args, PyObject* kw)
return result;

failed:
Py_DECREF(keys);
Py_XDECREF(keys);
Py_DECREF(result);
return NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions Modules/audioop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 1 addition & 1 deletion Modules/regexmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ regex_symcomp(PyObject *self, PyObject *args)

gdict = PyDict_New();
if (gdict == NULL || (npattern = symcomp(pattern, gdict)) == NULL) {
Py_DECREF(gdict);
Py_XDECREF(gdict);
Py_DECREF(pattern);
return NULL;
}
Expand Down

0 comments on commit 4523966

Please sign in to comment.