trace-cruncher: Fix segfault in PyTraceHist_read()
PATCH 1/2 trace-cruncher: Fix segfault in PyTraceHist_read()
A NULL pointer can be returned when reading from the 'hist' file of the event. This may happen if the histogram is not initialized.
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>
--- src/ftracepy-utils.c | 3 +++ 1 file changed, 3 insertions(+)
src/ftracepy-utils.c +3 -0
@@ -978,6 +978,9 @@ PyObject *PyTraceHist_read(PyTraceHist *self, PyObject *args, PyObject *kwargs) {char *data =hist_read (self, args, kwargs); +if (!data) +return NULL ; +PyObject *ret =PyUnicode_FromString (data);free (data);
Signature · 1 line
2.32.0
PATCH 2/2 trace-cruncher: Add more histogram tests
Testing the handling of couple of error cases.
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>
--- .../tests/1_unit/test_01_ftracepy_unit.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
tracecruncher/tests/1_unit/test_01_ftracepy_unit.py +18 -0
@@ -582,5 +582,23 @@ class HistTestCase(unittest.TestCase): self.assertTrue('Available triggers:' in h_buff) f.close() + def test_hist_err(self): + inst = ft.create_instance(instance_name) + hist = ft.hist(system='kmem', event='kmalloc', + axes={'call_site': 'sym', + 'bytes_alloc': 'n'}) + err = 'Failed read data from histogram' + with self.assertRaises(Exception) as context: + hist.read(inst) + self.assertTrue(err in str(context.exception)) + + hist.start(inst) + err = 'Failed to start filling the histogram' + with self.assertRaises(Exception) as context: + hist.start(inst) + self.assertTrue(err in str(context.exception)) + hist.close(inst) + + if __name__ == '__main__': unittest.main()
Signature · 1 line
2.32.0