]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python:tests: Catch strings passed to utf16_encoded_len() with embedded nulls
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Fri, 8 Dec 2023 01:44:48 +0000 (14:44 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 21 Dec 2023 20:21:34 +0000 (20:21 +0000)
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/ndr/gkdi.py

index a02a99fb4928726027dc997e0e075a11fcbb7d82..fc88df93ae285b86a41e2288ee9f6537e4cc805a 100755 (executable)
@@ -30,6 +30,9 @@ import samba.tests
 def utf16_encoded_len(s: str) -> int:
     """Return the number of bytes required to encode a string as null‐terminated
     UTF‐16."""
+    if "\x00" in s:
+        raise ValueError("string contains an embedded null")
+
     return len(s.encode("utf-16-le")) + 2