Skip to content

os.path.realpath can't handle symlink loops #40123

Closed

Description

@akuchling
BPO 930024
Nosy @loewis, @akuchling, @brettcannon, @barneygale
PRs
  • bpo-43757: make pathlib use os.path.realpath() to resolve all symlinks in a path #25264
  • Files
  • posixpath.patch: Patch fixing os.path.realpath
  • 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 = 'https://github.com/akuchling'
    closed_at = <Date 2021-04-08.02:12:01.014>
    created_at = <Date 2004-04-05.20:59:41.000>
    labels = ['library']
    title = "os.path.realpath can't handle symlink loops"
    updated_at = <Date 2021-04-08.02:12:01.014>
    user = 'https://github.com/akuchling'

    bugs.python.org fields:

    activity = <Date 2021-04-08.02:12:01.014>
    actor = 'barneygale'
    assignee = 'akuchling'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2004-04-05.20:59:41.000>
    creator = 'akuchling'
    dependencies = []
    files = ['1247']
    hgrepos = []
    issue_num = 930024
    keywords = []
    message_count = 5.0
    messages = ['20433', '20434', '20435', '20436', '20437']
    nosy_count = 4.0
    nosy_names = ['loewis', 'akuchling', 'brett.cannon', 'barneygale']
    pr_nums = ['25264']
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue930024'
    versions = ['Python 2.4']

    Activity

    1. akuchling commented on Apr 5, 2004

      @akuchling
      ContributorAuthor

      Create a symlink pointing to itself:

      ln -s infinite infinite

      Run os.path.realpath() on it, and it recurses
      infinitely (until the stack limit is hit):

      >>> import os
      >>> os.path.realpath('/home/amk/infinite')
      Traceback (most recent call last):
        File "<stdin>", line 1, in ?
        File "/usr/lib/python2.3/posixpath.py", line 416, in
      realpath
          return realpath(newpath)

      os.path.realpath() should be fixed; /home/amk/infinite
      is a perfectly good path, though it can't be followed.

    2. self-assigned this
      on Apr 5, 2004
    3. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Apr 5, 2004
    4. self-assigned this
      on Apr 5, 2004
    5. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Apr 5, 2004
    6. akuchling commented on Jun 5, 2004

      @akuchling
      ContributorAuthor

      Logged In: YES
      user_id=11375

      Patch attached; review requested.

    7. brettcannon commented on Jul 10, 2004

      @brettcannon
      Member

      Logged In: YES
      user_id=357491

      Applied as rev. 1.67 in 2.4a2 and rev. 1.62.6.2 in 2.3.5 with only minor
      cleanup.

    8. loewis commented on Aug 2, 2004

      loewismannequin
      Mannequin

      Logged In: YES
      user_id=21627

      The code that has been committed is incorrect if the link to
      be resolved is relative. _resolve_link uses abspath to
      determine whether the link is absolute. This function
      returns an absolute path (possibly using getcwd); the
      function that should have been used is isabs().

    9. akuchling commented on Aug 3, 2004

      @akuchling
      ContributorAuthor

      Logged In: YES
      user_id=11375

      Fixed in 2.3-maint and on the trunk.

    10. transferred this issue fromon Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    stdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions