cpython/Parser/lexer
Miss Islington (bot) 70ecd56113
[3.14] gh-144759: Fix undefined behavior from NULL pointer arithmetic in lexer (GH-144788) (#144834)
gh-144759: Fix undefined behavior from NULL pointer arithmetic in lexer (GH-144788)

Guard against NULL pointer arithmetic in `_PyLexer_remember_fstring_buffers`
and `_PyLexer_restore_fstring_buffers`. When `start` or `multi_line_start`
are NULL (uninitialized in tok_mode_stack[0]), performing `NULL - tok->buf`
is undefined behavior. Add explicit NULL checks to store -1 as sentinel
and restore NULL accordingly.

Add test_lexer_buffer_realloc_with_null_start to test_repl.py that
exercises the code path where the lexer buffer is reallocated while
tok_mode_stack[0] has NULL start/multi_line_start pointers. This
triggers _PyLexer_remember_fstring_buffers and verifies the NULL
checks prevent undefined behavior.
(cherry picked from commit e6110efd03)

Co-authored-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com>
2026-02-15 15:10:15 +00:00
..
buffer.c [3.14] gh-144759: Fix undefined behavior from NULL pointer arithmetic in lexer (GH-144788) (#144834) 2026-02-15 15:10:15 +00:00
buffer.h gh-104169: Refactor tokenizer into lexer and wrappers (#110684) 2023-10-11 15:14:44 +00:00
lexer.c [3.14] gh-140576: Fixed crash produced by lexer in case of dedented zero byte (GH-140583) (#140757) 2025-10-29 13:54:37 +00:00
lexer.h gh-132661: Implement PEP 750 (#132662) 2025-04-30 11:46:41 +02:00
state.c gh-132661: Implement PEP 750 (#132662) 2025-04-30 11:46:41 +02:00
state.h [3.14] gh-139516: Fix lambda colon start format spec in f-string in tokenizer (GH-139657) (#139701) 2025-10-07 18:35:17 +01:00