Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-118447: Fix handling of unreadable symlinks in os.path.realpath() #118489

Merged
merged 8 commits into from
May 18, 2024

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented May 1, 2024

@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label May 1, 2024
@barneygale barneygale changed the title GH-118447: Handle unreadable symlinks in os.path.realpath() GH-118447: Fix handling of unreadable symlinks in os.path.realpath() May 1, 2024
@barneygale barneygale removed the tests Tests in the Lib/test dir label May 1, 2024
@barneygale barneygale marked this pull request as ready for review May 1, 2024 22:06
nineteendo

This comment was marked as resolved.

@barneygale
Copy link
Contributor Author

If not resolving unreadable symlinks is acceptable, you still need to raise an error for link/...

realpath() shouldn't raise OSError in non-strict mode.

Lib/posixpath.py Outdated Show resolved Hide resolved
Lib/test/test_posixpath.py Show resolved Hide resolved
Lib/test/test_posixpath.py Show resolved Hide resolved
Copy link
Contributor

@nineteendo nineteendo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, you're right, it shouldn't raise an error. That's what strict is for.

@serhiy-storchaka
Copy link
Member

I think that it is reasonable to expect that realpath('dir/badlink/rest') returns the same result when badlink does not exist, is a file, is in non-readable directory or is non-readable itself, for any rest. It's error prone, but that's how it was defined.

Copy link
Contributor

@nineteendo nineteendo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Barney, would you like to continue working on this? You have my approval if it means anything.

@barneygale barneygale added needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels May 18, 2024
@barneygale barneygale enabled auto-merge (squash) May 18, 2024 22:26
@barneygale
Copy link
Contributor Author

Thanks for the reviews and suggestions, both!

@barneygale barneygale merged commit caf6064 into python:main May 18, 2024
35 checks passed
@miss-islington-app
Copy link

Thanks @barneygale for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 18, 2024
…path()` (pythonGH-118489)

(cherry picked from commit caf6064)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
@miss-islington-app
Copy link

Sorry, @barneygale, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker caf6064a1bc15ac344afd78b780188e60b9c628e 3.12

@bedevere-app
Copy link

bedevere-app bot commented May 18, 2024

GH-119163 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 18, 2024
barneygale added a commit to barneygale/cpython that referenced this pull request May 18, 2024
…path()` (python#118489)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
(cherry picked from commit caf6064)
barneygale added a commit to barneygale/cpython that referenced this pull request May 18, 2024
…th.realpath()` (pythonGH-118489)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>.
(cherry picked from commit caf6064)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
@barneygale
Copy link
Contributor Author

If no one objects, I'll skip backporting to 3.12 as this is a fairly minor bug and I can't be bothered to fix the conflicts :)

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD 3.x has failed when building commit caf6064.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1223/builds/3134) and take a look at the build logs.
  4. Check if the failure is related to this commit (caf6064) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1223/builds/3134

Failed tests:

  • test_posixpath

Failed subtests:

  • test_realpath_unreadable_symlink - test.test_posixpath.PosixPathTest.test_realpath_unreadable_symlink

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-freebsd/build/Lib/test/test_posixpath.py", line 670, in test_realpath_unreadable_symlink
    self.assertEqual(realpath(ABSTFN), ABSTFN)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/bui[19 chars].ware-freebsd/build/build/test_python_57143æ/@test_57143_tmpæ1' != '/bui[19 chars].ware-freebsd/build/build/test_python_57143æ/@test_57143_tmpæ'
- /buildbot/buildarea/3.x.ware-freebsd/build/build/test_python_57143æ/@test_57143_tmpæ1
?                                                                                     -
+ /buildbot/buildarea/3.x.ware-freebsd/build/build/test_python_57143æ/@test_57143_tmpæ


Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-freebsd/build/Lib/test/test_posixpath.py", line 670, in test_realpath_unreadable_symlink
    self.assertEqual(realpath(ABSTFN), ABSTFN)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/bui[19 chars].ware-freebsd/build/build/test_python_66351æ/@test_66351_tmpæ1' != '/bui[19 chars].ware-freebsd/build/build/test_python_66351æ/@test_66351_tmpæ'
- /buildbot/buildarea/3.x.ware-freebsd/build/build/test_python_66351æ/@test_66351_tmpæ1
?                                                                                     -
+ /buildbot/buildarea/3.x.ware-freebsd/build/build/test_python_66351æ/@test_66351_tmpæ

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD14 3.x has failed when building commit caf6064.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1232/builds/2352) and take a look at the build logs.
  4. Check if the failure is related to this commit (caf6064) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1232/builds/2352

Failed tests:

  • test_posixpath

Failed subtests:

  • test_realpath_unreadable_symlink - test.test_posixpath.PosixPathTest.test_realpath_unreadable_symlink

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14/build/Lib/test/test_posixpath.py", line 670, in test_realpath_unreadable_symlink
    self.assertEqual(realpath(ABSTFN), ABSTFN)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/hom[24 chars].opsec-fbsd14/build/build/test_python_79925æ/@test_79925_tmpæ1' != '/hom[24 chars].opsec-fbsd14/build/build/test_python_79925æ/@test_79925_tmpæ'
- /home/buildbot/buildarea/3.x.opsec-fbsd14/build/build/test_python_79925æ/@test_79925_tmpæ1
?                                                                                          -
+ /home/buildbot/buildarea/3.x.opsec-fbsd14/build/build/test_python_79925æ/@test_79925_tmpæ


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14/build/Lib/test/test_posixpath.py", line 670, in test_realpath_unreadable_symlink
    self.assertEqual(realpath(ABSTFN), ABSTFN)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/hom[24 chars].opsec-fbsd14/build/build/test_python_75684æ/@test_75684_tmpæ1' != '/hom[24 chars].opsec-fbsd14/build/build/test_python_75684æ/@test_75684_tmpæ'
- /home/buildbot/buildarea/3.x.opsec-fbsd14/build/build/test_python_75684æ/@test_75684_tmpæ1
?                                                                                          -
+ /home/buildbot/buildarea/3.x.opsec-fbsd14/build/build/test_python_75684æ/@test_75684_tmpæ

barneygale added a commit that referenced this pull request May 18, 2024
…lpath()` (GH-118489) (#119163)

(cherry picked from commit caf6064)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD 3.13 has failed when building commit 7407267.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1491/builds/46) and take a look at the build logs.
  4. Check if the failure is related to this commit (7407267) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1491/builds/46

Failed tests:

  • test_posixpath

Failed subtests:

  • test_realpath_unreadable_symlink - test.test_posixpath.PosixPathTest.test_realpath_unreadable_symlink

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/buildbot/buildarea/3.13.ware-freebsd/build/Lib/test/test_posixpath.py", line 670, in test_realpath_unreadable_symlink
    self.assertEqual(realpath(ABSTFN), ABSTFN)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/bui[20 chars].ware-freebsd/build/build/test_python_84680æ/@test_84680_tmpæ1' != '/bui[20 chars].ware-freebsd/build/build/test_python_84680æ/@test_84680_tmpæ'
- /buildbot/buildarea/3.13.ware-freebsd/build/build/test_python_84680æ/@test_84680_tmpæ1
?                                                                                      -
+ /buildbot/buildarea/3.13.ware-freebsd/build/build/test_python_84680æ/@test_84680_tmpæ


Traceback (most recent call last):
  File "/buildbot/buildarea/3.13.ware-freebsd/build/Lib/test/test_posixpath.py", line 670, in test_realpath_unreadable_symlink
    self.assertEqual(realpath(ABSTFN), ABSTFN)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/bui[20 chars].ware-freebsd/build/build/test_python_77930æ/@test_77930_tmpæ1' != '/bui[20 chars].ware-freebsd/build/build/test_python_77930æ/@test_77930_tmpæ'
- /buildbot/buildarea/3.13.ware-freebsd/build/build/test_python_77930æ/@test_77930_tmpæ1
?                                                                                      -
+ /buildbot/buildarea/3.13.ware-freebsd/build/build/test_python_77930æ/@test_77930_tmpæ

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD14 3.13 has failed when building commit 7407267.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1481/builds/45) and take a look at the build logs.
  4. Check if the failure is related to this commit (7407267) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1481/builds/45

Failed tests:

  • test_posixpath

Failed subtests:

  • test_realpath_unreadable_symlink - test.test_posixpath.PosixPathTest.test_realpath_unreadable_symlink

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.opsec-fbsd14/build/Lib/test/test_posixpath.py", line 670, in test_realpath_unreadable_symlink
    self.assertEqual(realpath(ABSTFN), ABSTFN)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/hom[25 chars].opsec-fbsd14/build/build/test_python_95351æ/@test_95351_tmpæ1' != '/hom[25 chars].opsec-fbsd14/build/build/test_python_95351æ/@test_95351_tmpæ'
- /home/buildbot/buildarea/3.13.opsec-fbsd14/build/build/test_python_95351æ/@test_95351_tmpæ1
?                                                                                           -
+ /home/buildbot/buildarea/3.13.opsec-fbsd14/build/build/test_python_95351æ/@test_95351_tmpæ


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.opsec-fbsd14/build/Lib/test/test_posixpath.py", line 670, in test_realpath_unreadable_symlink
    self.assertEqual(realpath(ABSTFN), ABSTFN)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/hom[25 chars].opsec-fbsd14/build/build/test_python_94029æ/@test_94029_tmpæ1' != '/hom[25 chars].opsec-fbsd14/build/build/test_python_94029æ/@test_94029_tmpæ'
- /home/buildbot/buildarea/3.13.opsec-fbsd14/build/build/test_python_94029æ/@test_94029_tmpæ1
?                                                                                           -
+ /home/buildbot/buildarea/3.13.opsec-fbsd14/build/build/test_python_94029æ/@test_94029_tmpæ

estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…path()` (python#118489)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs backport to 3.12 bug and security fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants