aboutsummaryrefslogtreecommitdiff
path: root/py/objtype.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-02-07 15:44:29 +1100
committerDamien George <damien.p.george@gmail.com>2018-02-07 15:44:29 +1100
commitb45c8c17f0f295e919a90659d4c1880a47b228c1 (patch)
tree97baec306a8914ce429d3802862239b2bf4b485c /py/objtype.c
parentcc92c0572e2b6dba3c5897d5778704aaccbb567e (diff)
py/objtype: Check and prevent delete/store on a fixed locals map.
Note that the check for elem!=NULL is removed for the MP_MAP_LOOKUP_ADD_IF_NOT_FOUND case because mp_map_lookup will always return non-NULL for such a case.
Diffstat (limited to 'py/objtype.c')
-rw-r--r--py/objtype.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/py/objtype.c b/py/objtype.c
index 33757287a..7df349ce9 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -975,21 +975,21 @@ STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
if (self->locals_dict != NULL) {
assert(self->locals_dict->base.type == &mp_type_dict); // MicroPython restriction, for now
mp_map_t *locals_map = &self->locals_dict->map;
+ if (locals_map->is_fixed) {
+ // can't apply delete/store to a fixed map
+ return;
+ }
if (dest[1] == MP_OBJ_NULL) {
// delete attribute
mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP_REMOVE_IF_FOUND);
- // note that locals_map may be in ROM, so remove will fail in that case
if (elem != NULL) {
dest[0] = MP_OBJ_NULL; // indicate success
}
} else {
// store attribute
mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
- // note that locals_map may be in ROM, so add will fail in that case
- if (elem != NULL) {
- elem->value = dest[1];
- dest[0] = MP_OBJ_NULL; // indicate success
- }
+ elem->value = dest[1];
+ dest[0] = MP_OBJ_NULL; // indicate success
}
}
}