From b86c65d31c61af42a3b634c6a3150917509e3e8b Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 3 Jul 2017 14:52:00 +1000 Subject: 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. --- extmod/modubinascii.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'extmod') 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) { -- cgit v1.2.3