Skip to content

NULL + 1 in _PyFunction_FastCallDict(), PyEval_EvalCodeEx() #74825

Closed

Description

@serhiy-storchaka
BPO 30640
Nosy @vstinner, @serhiy-storchaka, @ZackerySpytz
PRs
  • bpo-30640: Fix undefined behavior in _PyFunction_FastCallDict(), PyEval_EvalCodeEx() #2919
  • [3.6] bpo-30640: Fix undefined behavior in _PyFunction_FastCallDict()… #2964
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-09-08.01:19:03.544>
    created_at = <Date 2017-06-12.14:37:59.165>
    labels = ['interpreter-core', '3.7']
    title = 'NULL + 1 in _PyFunction_FastCallDict(), PyEval_EvalCodeEx()'
    updated_at = <Date 2017-09-08.01:19:03.543>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2017-09-08.01:19:03.543>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-09-08.01:19:03.544>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2017-06-12.14:37:59.165>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30640
    keywords = []
    message_count = 7.0
    messages = ['295786', '295788', '295794', '299538', '299556', '301663', '301664']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'serhiy.storchaka', 'ZackerySpytz']
    pr_nums = ['2919', '2964']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue30640'
    versions = ['Python 3.7']

    Activity

    1. serhiy-storchaka commented on Jun 12, 2017

      @serhiy-storchaka
      MemberAuthor

      In _PyFunction_FastCallDict() if nk == 0, k is set to NULL. After that k + 1 is passed to _PyEval_EvalCodeWithName(). NULL + 1 is an undefined behavior.

    2. added
      3.7 (EOL)
      interpreter-core
      on Jun 12, 2017
    3. changed the title [-]NULL + 1[/-] [+]NULL + 1 in _PyFunction_FastCallDict()[/+] on Jun 12, 2017
    4. vstinner commented on Jun 12, 2017

      @vstinner
      Member

      Can you please show me the line doing NULL+1? I don't see it. Or do you mean the "k + 1" with k=NULL?

      _PyEval_EvalCodeWithName() ignores kwnames and kwargs when kwcount is zero. So I don't think that the value of NULL+1 matters here :-)

    5. serhiy-storchaka commented on Jun 12, 2017

      @serhiy-storchaka
      MemberAuthor

      Yes, I mean the "k + 1" with k=NULL.

      Even if _PyEval_EvalCodeWithName() ignores that value, this still is an undefined behavior. For example the compiler can decide that since NULL+1 is not valid, then k never is NULL, and ignore the branch that sets k to NULL. It can also not generate the code in _PyEval_EvalCodeWithName() for handling the case kwcount == 0.

    6. ZackerySpytz commented on Jul 31, 2017

      ZackerySpytzmannequin
      Mannequin

      As mentioned in PR 2919, this is an issue in PyEval_EvalCodeEx() as well.

    7. changed the title [-]NULL + 1 in _PyFunction_FastCallDict()[/-] [+]NULL + 1 in _PyFunction_FastCallDict(), PyEval_EvalCodeEx()[/+] on Jul 31, 2017
    8. serhiy-storchaka commented on Jul 31, 2017

      @serhiy-storchaka
      MemberAuthor

      New changeset c6ea897 by Serhiy Storchaka (Zackery Spytz) in branch 'master':
      bpo-30640: Fix undefined behavior in _PyFunction_FastCallDict() and PyEval_EvalCodeEx() (bpo-2919)
      c6ea897

    9. vstinner commented on Sep 8, 2017

      @vstinner
      Member

      New changeset f032e92 by Victor Stinner (Zackery Spytz) in branch '3.6':
      [3.6] bpo-30640: Fix undefined behavior in _PyFunction_FastCallDict() and PyEval_EvalCodeEx() (GH-2919) (bpo-2964)
      f032e92

    10. vstinner commented on Sep 8, 2017

      @vstinner
      Member

      It's now fixed in Python 3.6 and master (3.7).

      FYI this issue was also detected by Coverity as CID 1415964.

    11. transferred this issue fromon Apr 10, 2022
    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.7 (EOL)interpreter-core

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions