summaryrefslogtreecommitdiffstatshomepage
path: root/tests
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 /tests
parente4ab404780dfa194864c579407a054cf6c75db3a (diff)
downloadmicropython-025e5f2b339377ebc54ebc9cab2612946145a6fa.tar.gz
micropython-025e5f2b339377ebc54ebc9cab2612946145a6fa.zip
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 'tests')
-rw-r--r--tests/basics/struct2.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/basics/struct2.py b/tests/basics/struct2.py
index d8234d0d36..3b9dd5c1f6 100644
--- a/tests/basics/struct2.py
+++ b/tests/basics/struct2.py
@@ -40,3 +40,30 @@ try:
struct.calcsize('0z')
except:
print('Exception')
+
+# check that a count without a type specifier raises an exception
+
+try:
+ struct.calcsize('1')
+except:
+ print('Exception')
+
+try:
+ struct.pack('1')
+except:
+ print('Exception')
+
+try:
+ struct.pack_into('1', bytearray(4), 0, 'xx')
+except:
+ print('Exception')
+
+try:
+ struct.unpack('1', 'xx')
+except:
+ print('Exception')
+
+try:
+ struct.unpack_from('1', 'xx')
+except:
+ print('Exception')