summaryrefslogtreecommitdiff
path: root/py/binary.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-08-17 16:16:11 +1000
committerDamien George <damien.p.george@gmail.com>2017-08-17 16:19:35 +1000
commit025e5f2b339377ebc54ebc9cab2612946145a6fa (patch)
treec0238789e9ae5c6ae86789c34a55377bc176c5e4 /py/binary.h
parente4ab404780dfa194864c579407a054cf6c75db3a (diff)
py/binary: Change internal bytearray typecode from 0 to 1.
The value of 0 can't be used because otherwise mp_binary_get_size will let a null byte through as the type code (intepreted as byterray). This can lead to invalid type-specifier strings being let through without an error in the struct module, and even buffer overruns.
Diffstat (limited to 'py/binary.h')
-rw-r--r--py/binary.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/py/binary.h b/py/binary.h
index 7b5c60f1a..0dae6a29e 100644
--- a/py/binary.h
+++ b/py/binary.h
@@ -29,8 +29,9 @@
#include "py/obj.h"
// Use special typecode to differentiate repr() of bytearray vs array.array('B')
-// (underlyingly they're same).
-#define BYTEARRAY_TYPECODE 0
+// (underlyingly they're same). Can't use 0 here because that's used to detect
+// type-specification errors due to end-of-string.
+#define BYTEARRAY_TYPECODE 1
size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign);
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index);