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..9364570a954814f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-25-07-22-05.gh-issue-150372.9hLqhe.rst @@ -0,0 +1,3 @@ +Fix missing null check on the result of :func:`!strdup` in +:mod:`readline` module initialization, preventing a potential null pointer +dereference on memory allocation failure. diff --git a/Modules/readline.c b/Modules/readline.c index 488332f548e5fe3..419d3a36a1b161b 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -1404,6 +1404,11 @@ setup_readline(readlinestate *mod_state) completer_word_break_characters = strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?"); /* All nonalphanums except '.' */ + + if (!completer_word_break_characters) { + RESTORE_LOCALE(saved_locale) + return -1; + } #ifdef WITH_EDITLINE // libedit uses rl_basic_word_break_characters instead of // rl_completer_word_break_characters as complete delimiter