From: Joseph Sutton Date: Fri, 8 Dec 2023 01:44:48 +0000 (+1300) Subject: python:tests: Catch strings passed to utf16_encoded_len() with embedded nulls X-Git-Tag: talloc-2.4.2~210 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=858f70037bdc56d06b7fd2fae12b213caac8628a;p=thirdparty%2Fsamba.git python:tests: Catch strings passed to utf16_encoded_len() with embedded nulls Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/ndr/gkdi.py b/python/samba/tests/ndr/gkdi.py index a02a99fb492..fc88df93ae2 100755 --- a/python/samba/tests/ndr/gkdi.py +++ b/python/samba/tests/ndr/gkdi.py @@ -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