Skip to content

Conversation

@ashm-dev
Copy link
Contributor

@ashm-dev ashm-dev commented Nov 13, 2025

Fixes buffer overflow (CVE-2006-1542) in _Py_wrealpath() when handling paths longer than MAXPATHLEN (4096 bytes).

Changed realpath(path, buffer) to realpath(path, NULL) for dynamic allocation.

Closes #42400

Allow platforms where realpath returns different canonical paths (e.g.
Android). Verify resolution with os.samefile and fall back to a length
check if samefile is unavailable.
@ashm-dev
Copy link
Contributor Author

I don't think the errors in the UBSAN test are related to this fix, as they occur for a completely different reason and generally in import tests.

@ashm-dev
Copy link
Contributor Author

@vstinner Could you please review this PR?

@ashm-dev ashm-dev requested a review from vstinner November 14, 2025 11:08
@vstinner
Copy link
Member

I updated the PR to retrieve the fix for the UBSan CI.

@vstinner vstinner added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 17, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @vstinner for commit f882e26 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F141529%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 17, 2025
@vstinner
Copy link
Member

realpath(path, NULL) seems to be a recent feature. Let me check on buildbots if it's supported by all platforms supported by Python.

@vstinner vstinner merged commit daafacf into python:main Nov 18, 2025
112 of 118 checks passed
@vstinner
Copy link
Member

Change merged, thanks.

The change passed on our fleet of stable buildbots.

Even if the change was documented in the Security category, I don't think that it's worth it to backport it to stable branches (yet). I'm afraid of breaking the Python build on some weird platforms where realpath(path, NULL) is not supported. So I prefer to make the change only in the main branch for now.

@ashm-dev ashm-dev deleted the fix/cve-realpath branch November 18, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid using unsafe realpath

3 participants