Mercurial > hg > octave-lojdl
changeset 15613:126285fce876
check for allowed struct field names in subsref and subsasgn
* ov-struct.cc (octave_scalar_struct::dotref): Check if the provided
field name is valid. (octave_scalar_struct::subsasgn) Ditto.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 15 Nov 2012 13:07:24 -0500 |
parents | 8b04a7d67d8a |
children | f2b8f90052fd 9671baab36c4 |
files | libinterp/octave-value/ov-struct.cc |
diffstat | 1 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.cc +++ b/libinterp/octave-value/ov-struct.cc @@ -1093,11 +1093,19 @@ octave_value octave_scalar_struct::dotref (const octave_value_list& idx, bool auto_add) { + octave_value retval; + assert (idx.length () == 1); std::string nm = idx(0).string_value (); - octave_value retval = map.getfield (nm); + if (! valid_identifier (nm)) + { + error ("subsref: invalid structure field name '%s'", nm.c_str ()); + return retval; + } + + retval = map.getfield (nm); if (! auto_add && retval.is_undefined ()) error ("structure has no member '%s'", nm.c_str ()); @@ -1218,6 +1226,12 @@ std::string key = key_idx(0).string_value (); + if (! valid_identifier (key)) + { + error ("subsasgn: invalid structure field name '%s'", key.c_str ()); + return retval; + } + if (n > 1) { std::list<octave_value_list> next_idx (idx);