[3.7] bpo-35214: Fix OOB memory access in unicode escape parser (GH-10506) (GH-10522)

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"'
(cherry picked from commit 746b2d35ea)


Co-authored-by: Gregory P. Smith <greg@krypto.org>


https://bugs.python.org/issue35214
This commit is contained in:
Miss Islington (bot) 2018-11-13 16:39:36 -08:00 committed by GitHub
parent c30830bbb2
commit 9fbcb1402e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -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.

View File

@ -6042,7 +6042,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 */