From 2e4d963fb27e10835c44564788b9c3d25bc21119 Mon Sep 17 00:00:00 2001 From: Phil Muldoon Date: Mon, 21 Sep 2009 09:32:28 +0000 Subject: 2009-09-21 Phil Muldoon * python/py-value.c (valpy_getitem): Test value before allowing subscript operation. 2009-09-21 Phil Muldoon * gdb.python/py-value.exp (test_subscript_regression): New function. Test for invalid subscripts. * gdb.python/py-value.c (main): Add test array, and pointer to it. (ptr_ref): New function. --- gdb/python/py-value.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'gdb/python/py-value.c') diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 3d88aa3..714aa11 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -324,7 +324,18 @@ valpy_getitem (PyObject *self, PyObject *key) type. */ struct value *idx = convert_value_from_python (key); if (idx != NULL) - res_val = value_subscript (tmp, value_as_long (idx)); + { + /* Check the value's type is something that can be accessed via + a subscript. */ + struct type *type; + tmp = coerce_ref (tmp); + type = check_typedef (value_type (tmp)); + if (TYPE_CODE (type) != TYPE_CODE_ARRAY + && TYPE_CODE (type) != TYPE_CODE_PTR) + error( _("Cannot subscript requested type")); + else + res_val = value_subscript (tmp, value_as_long (idx)); + } } } -- cgit v1.1