diff options
author | Damien George <damien.p.george@gmail.com> | 2018-03-30 11:09:00 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-03-30 11:13:32 +1100 |
commit | 32807881954f106b9735de74fe984062a0815b81 (patch) | |
tree | 191a534e36c54c7c26005864045996fc87f6abb8 /py/objstr.c | |
parent | bc3a5f191714f28bef95d9f87c24f7367c90d54a (diff) |
py/runtime: Check that keys in dicts passed as ** args are strings.
Prior to this patch the code would crash if a key in a ** dict was anything
other than a str or qstr. This is because mp_setup_code_state() assumes
that keys in kwargs are qstrs (for efficiency).
Thanks to @jepler for finding the bug.
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index c42f38e75..0b11533f8 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -2062,6 +2062,12 @@ mp_obj_t mp_obj_str_intern(mp_obj_t str) { return mp_obj_new_str_via_qstr((const char*)data, len); } +mp_obj_t mp_obj_str_intern_checked(mp_obj_t obj) { + size_t len; + const char *data = mp_obj_str_get_data(obj, &len); + return mp_obj_new_str_via_qstr((const char*)data, len); +} + mp_obj_t mp_obj_new_bytes(const byte* data, size_t len) { return mp_obj_new_str_copy(&mp_type_bytes, data, len); } |