diff options
author | Damien George <damien.p.george@gmail.com> | 2017-07-03 14:52:00 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-07-03 14:52:00 +1000 |
commit | b86c65d31c61af42a3b634c6a3150917509e3e8b (patch) | |
tree | af3cc988d8b1117c62f8c22f1430644325433966 /extmod/modubinascii.c | |
parent | 45b127e7ac95308b51364b22f174c8b15d1f8e89 (diff) |
extmod/modubinascii: Add check for empty buffer passed to hexlify.
Previous to this patch hexlify(b'', b':') would lead to a bad crash due to
the computed length of the result being -1=0xffffffff.
Diffstat (limited to 'extmod/modubinascii.c')
-rw-r--r-- | extmod/modubinascii.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/extmod/modubinascii.c b/extmod/modubinascii.c index 07b8b15bf..cf250d27f 100644 --- a/extmod/modubinascii.c +++ b/extmod/modubinascii.c @@ -42,6 +42,12 @@ mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ); + // Code below assumes non-zero buffer length when computing size with + // separator, so handle the zero-length case here. + if (bufinfo.len == 0) { + return mp_const_empty_bytes; + } + vstr_t vstr; size_t out_len = bufinfo.len * 2; if (n_args > 1) { |