]> granicus.if.org Git - python/commitdiff
bpo-35214: Fix OOB memory access in unicode escape parser (GH-10506)
authorGregory P. Smith <greg@krypto.org>
Tue, 13 Nov 2018 21:16:54 +0000 (13:16 -0800)
committerGitHub <noreply@github.com>
Tue, 13 Nov 2018 21:16:54 +0000 (13:16 -0800)
Discovered using clang's MemorySanitizer when it ran python3's
test_fstring test_misformed_unicode_character_name.

An msan build will fail by simply executing: ./python -c 'u"\N"'

Misc/NEWS.d/next/Core and Builtins/2018-11-13-00-40-35.bpo-35214.OQBjph.rst [new file with mode: 0644]
Objects/unicodeobject.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-11-13-00-40-35.bpo-35214.OQBjph.rst b/Misc/NEWS.d/next/Core and Builtins/2018-11-13-00-40-35.bpo-35214.OQBjph.rst
new file mode 100644 (file)
index 0000000..d462c97
--- /dev/null
@@ -0,0 +1,3 @@
+Fixed an out of bounds memory access when parsing a truncated unicode
+escape sequence at the end of a string such as ``'\N'``.  It would read
+one byte beyond the end of the memory allocation.
index e5d026f9aa0e5d01ebeb961b2e78bef50f24966b..04ca5f3344470e7b14d72654f60b49a01de99831 100644 (file)
@@ -6069,7 +6069,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
             }
 
             message = "malformed \\N character escape";
-            if (*s == '{') {
+            if (s < end && *s == '{') {
                 const char *start = ++s;
                 size_t namelen;
                 /* look for the closing brace */