From 858f70037bdc56d06b7fd2fae12b213caac8628a Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Fri, 8 Dec 2023 14:44:48 +1300 Subject: [PATCH] python:tests: Catch strings passed to utf16_encoded_len() with embedded nulls Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- python/samba/tests/ndr/gkdi.py | 3 +++ 1 file changed, 3 insertions(+) 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 -- 2.47.3