summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_struct.py
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2020-05-25 07:55:09 (GMT)
committerGitHub <noreply@github.com>2020-05-25 07:55:09 (GMT)
commit3f59b55316f4c6ab451997902579aa69020b537c (patch)
tree1b3d9129922050565b1ae301916d3e540b81b9ba /Lib/test/test_struct.py
parent372ee27d4958302dac7ad6a8711f6fd04771b2e6 (diff)
downloadcpython-3f59b55316f4c6ab451997902579aa69020b537c.zip
cpython-3f59b55316f4c6ab451997902579aa69020b537c.tar.gz
cpython-3f59b55316f4c6ab451997902579aa69020b537c.tar.bz2
bpo-35714: Reject null characters in struct format strings (GH-16928)
struct.error is now raised if there is a null character in a struct format string.
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r--Lib/test/test_struct.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 4829fbe..b3f21ea 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -671,6 +671,14 @@ class StructTest(unittest.TestCase):
self.assertIn(b"Exception ignored in:", stderr)
self.assertIn(b"C.__del__", stderr)
+ def test_issue35714(self):
+ # Embedded null characters should not be allowed in format strings.
+ for s in '\0', '2\0i', b'\0':
+ with self.assertRaisesRegex(struct.error,
+ 'embedded null character'):
+ struct.calcsize(s)
+
+
class UnpackIteratorTest(unittest.TestCase):
"""
Tests for iterative unpacking (struct.Struct.iter_unpack).