Ack. Pushed.
On 04/30/2013 03:58 PM, Martin Milata wrote:
Previous commit 93d2ef8b730bc2659e348bce9f7ecfc902600b9d introduced
a
bug where an attempt to delete a computed attribute results in a
segmentation fault.
The setters in C bindings have been modified to check whether the new
parameter is NULL and throw an exception if it is.
Signed-off-by: Martin Milata <mmilata(a)redhat.com>
---
python/py_common.c | 24 ++++++++++++++++++++++++
python/py_gdb_sharedlib.c | 6 ++++++
tests/python/koops.py | 1 +
tests/python/test_helpers.py | 1 +
4 files changed, 32 insertions(+)
diff --git a/python/py_common.c b/python/py_common.c
index 15aa108..2b4dd9b 100644
--- a/python/py_common.c
+++ b/python/py_common.c
@@ -42,6 +42,12 @@ sr_py_getter_string(PyObject *self, void *data)
int
sr_py_setter_string(PyObject *self, PyObject *rhs, void *data)
{
+ if (rhs == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute.");
+ return -1;
+ }
+
struct getset_offsets *gsoff = data;
char *newvalue = PyString_AsString(rhs);
@@ -66,6 +72,12 @@ sr_py_getter_uint32(PyObject *self, void *data)
int
sr_py_setter_uint32(PyObject *self, PyObject *rhs, void *data)
{
+ if (rhs == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute.");
+ return -1;
+ }
+
struct getset_offsets *gsoff = data;
long newvalue = PyInt_AsLong(rhs);
@@ -95,6 +107,12 @@ sr_py_getter_bool(PyObject *self, void *data)
int
sr_py_setter_bool(PyObject *self, PyObject *rhs, void *data)
{
+ if (rhs == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute.");
+ return -1;
+ }
+
struct getset_offsets *gsoff = data;
bool newvalue = PyObject_IsTrue(rhs);
@@ -116,6 +134,12 @@ sr_py_getter_uint64(PyObject *self, void *data)
int
sr_py_setter_uint64(PyObject *self, PyObject *rhs, void *data)
{
+ if (rhs == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute.");
+ return -1;
+ }
+
struct getset_offsets *gsoff = data;
unsigned long long newvalue = PyInt_AsUnsignedLongLongMask(rhs);
diff --git a/python/py_gdb_sharedlib.c b/python/py_gdb_sharedlib.c
index 4d34278..da66c79 100644
--- a/python/py_gdb_sharedlib.c
+++ b/python/py_gdb_sharedlib.c
@@ -124,6 +124,12 @@ sr_py_gdb_sharedlib_get_symbols(PyObject *self, void *data)
int
sr_py_gdb_sharedlib_set_symbols(PyObject *self, PyObject *rhs, void *data)
{
+ if (rhs == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute.");
+ return -1;
+ }
+
long newvalue = PyInt_AsLong(rhs);
if (PyErr_Occurred())
return -1;
diff --git a/tests/python/koops.py b/tests/python/koops.py
index fbeb8dd..f0c6ac0 100755
--- a/tests/python/koops.py
+++ b/tests/python/koops.py
@@ -31,6 +31,7 @@ class TestKerneloops(BindingsTestCase):
## not implemented, expected to fail
#self.koops.modules = ['foo', 'bar']
#self.assertEqual(len(self.koops.modules), 2)
+ self.assertRaises(NotImplementedError, self.koops.__delattr__,
'modules')
def test_dup(self):
dup = self.koops.dup()
diff --git a/tests/python/test_helpers.py b/tests/python/test_helpers.py
index 4bd03a0..e8de55d 100644
--- a/tests/python/test_helpers.py
+++ b/tests/python/test_helpers.py
@@ -8,6 +8,7 @@ class BindingsTestCase(unittest.TestCase):
self.assertEqual(obj.__getattribute__(attr), orig_val)
obj.__setattr__(attr, new_val)
self.assertEqual(obj.__getattribute__(attr), new_val)
+ self.assertRaises(TypeError, obj.__delattr__, attr)
if __name__ == '__main__':
import sys
--
Richard Marko