aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2009-09-21 09:32:28 +0000
committerPhil Muldoon <pmuldoon@redhat.com>2009-09-21 09:32:28 +0000
commit2e4d963fb27e10835c44564788b9c3d25bc21119 (patch)
tree86fc576d3de53a708a84367fd5300e3abfcba5ce /gdb/python
parentcdfbdf303db54c1ab1ef02a44872976e0f119530 (diff)
downloadgdb-2e4d963fb27e10835c44564788b9c3d25bc21119.zip
gdb-2e4d963fb27e10835c44564788b9c3d25bc21119.tar.gz
gdb-2e4d963fb27e10835c44564788b9c3d25bc21119.tar.bz2
2009-09-21 Phil Muldoon <pmuldoon@redhat.com>
* python/py-value.c (valpy_getitem): Test value before allowing subscript operation. 2009-09-21 Phil Muldoon <pmuldoon@redhat.com> * 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.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-value.c13
1 files changed, 12 insertions, 1 deletions
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));
+ }
}
}