Skip to content

readline is missing a null pointer check on strdup return value #150372

Closed

Description

@KowalskiThomas

Bug report

Bug description:

In readline.c, a call is made to strdup to populate completer_word_break_characters, but the return value of strdup is never checked before being used. In strdup failed, it will lead to a hard crash.

cpython/Modules/readline.c

Lines 1404 to 1416 in 1d28f9a

completer_word_break_characters =
strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?");
/* All nonalphanums except '.' */
#ifdef WITH_EDITLINE
// libedit uses rl_basic_word_break_characters instead of
// rl_completer_word_break_characters as complete delimiter
rl_basic_word_break_characters = completer_word_break_characters;
#else
if (using_libedit_emulation) {
rl_basic_word_break_characters = completer_word_break_characters;
}
#endif
rl_completer_word_break_characters = completer_word_break_characters;

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-crashA hard crash of the interpreter, possibly with a core dump
    and removed
    type-bugAn unexpected behavior, bug, or error
    on May 25, 2026
  2. sergey-miryanov commented on May 25, 2026

    @sergey-miryanov
    Contributor

    Could you please check whether we should backport this fix?

  3. KowalskiThomas commented on May 25, 2026

    @KowalskiThomas
    ContributorAuthor

    Could you please check whether we should backport this fix?

    @sergey-miryanov I do believe this needs to be backported, it's in the same state on 3.15 / 3.14 / 3.13. If you consider it security and not a bug fix then probably even to older versions as well.

  4. added
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    on May 25, 2026
  5. sergey-miryanov commented on May 25, 2026

    @sergey-miryanov
    Contributor

    Thanks! I'm not sure this should be classified as a security bug.

  6. vstinner commented on May 28, 2026

    @vstinner
    Member

    We usually don't treat bugs related to memory allocation failures as security bugs. But it's worth it to backport the bugfix up to 3.13 branch.

  7. added 3 commits that reference this issue on May 30, 2026
  8. added a commit that references this issue on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions