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.
This commit is contained in:
parent
45b127e7ac
commit
b86c65d31c
|
@ -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) {
|
||||
|
|
|
@ -10,3 +10,6 @@ except ImportError:
|
|||
# two arguments supported in uPy but not CPython
|
||||
a = binascii.hexlify(b'123', ':')
|
||||
print(a)
|
||||
|
||||
# zero length buffer
|
||||
print(binascii.hexlify(b'', b':'))
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
b'31:32:33'
|
||||
b''
|
||||
|
|
Loading…
Reference in New Issue