1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

python:tests: Catch strings passed to utf16_encoded_len() with embedded nulls

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Joseph Sutton 2023-12-08 14:44:48 +13:00 committed by Andrew Bartlett
parent 27231a965e
commit 858f70037b

View File

@ -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 nullterminated
UTF16."""
if "\x00" in s:
raise ValueError("string contains an embedded null")
return len(s.encode("utf-16-le")) + 2