From a0b3c9c92e230bd08b469851de0bf51d26e10535 Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Sat, 30 May 2026 21:26:05 +0200 Subject: [PATCH] gh-150372: Add missing null check on completer_word_break_characters in readline.c (GH-150251) (cherry picked from commit 56bd9ea676d5ab4d5f6c68aefc3125ef5a216157) Co-authored-by: Thomas Kowalski --- .../2026-05-25-07-22-05.gh-issue-150372.9hLqhe.rst | 2 ++ Modules/readline.c | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-05-25-07-22-05.gh-issue-150372.9hLqhe.rst diff --git a/Misc/NEWS.d/next/Library/2026-05-25-07-22-05.gh-issue-150372.9hLqhe.rst b/Misc/NEWS.d/next/Library/2026-05-25-07-22-05.gh-issue-150372.9hLqhe.rst new file mode 100644 index 000000000000000..7b83bd8fe73f11d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-25-07-22-05.gh-issue-150372.9hLqhe.rst @@ -0,0 +1,2 @@ +:mod:`readline`: Fix a potential crash during tab completion caused by an +out-of-memory error during module initialization. diff --git a/Modules/readline.c b/Modules/readline.c index 8475846eefc905c..7708f47d4d03279 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -1382,6 +1382,10 @@ setup_readline(readlinestate *mod_state) completer_word_break_characters = strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?"); /* All nonalphanums except '.' */ + + if (!completer_word_break_characters) { + goto error; + } #ifdef WITH_EDITLINE // libedit uses rl_basic_word_break_characters instead of // rl_completer_word_break_characters as complete delimiter @@ -1425,6 +1429,10 @@ setup_readline(readlinestate *mod_state) RESTORE_LOCALE(saved_locale) return 0; + +error: + RESTORE_LOCALE(saved_locale) + return -1; } /* Wrapper around GNU readline that handles signals differently. */