]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-150372: Add missing null check on completer_word_break_characters in readline...
authorThomas Kowalski <thom.kowa@gmail.com>
Sat, 30 May 2026 19:26:05 +0000 (21:26 +0200)
committerGitHub <noreply@github.com>
Sat, 30 May 2026 19:26:05 +0000 (19:26 +0000)
Misc/NEWS.d/next/Library/2026-05-25-07-22-05.gh-issue-150372.9hLqhe.rst [new file with mode: 0644]
Modules/readline.c

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 (file)
index 0000000..7b83bd8
--- /dev/null
@@ -0,0 +1,2 @@
+:mod:`readline`: Fix a potential crash during tab completion caused by an
+out-of-memory error during module initialization.
index 2cc3d40baa3aba10cc1320df510c4e2fb2dc356e..c580d2022fccf3d6202865510e30f4e302eff35d 100644 (file)
@@ -1406,6 +1406,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
@@ -1449,6 +1453,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. */