Skip to content

gh-136062: Buffer Overflow Vulnerability in _Py_wreadlink Function #136064

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

Closed

Conversation

akshat62
Copy link
Contributor

@akshat62 akshat62 commented Jun 28, 2025

@akshat62 akshat62 closed this Jun 28, 2025
@@ -2102,7 +2102,8 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t buflen)
errno = EINVAL;
return -1;
}
wcsncpy(buf, wbuf, buflen);
wcsncpy(buf, wbuf, buflen - 1);
buf[buflen - 1] = L'\0'; /* Ensure null termination */
Copy link
Member

@picnixz picnixz Jun 28, 2025

Choose a reason for hiding this comment

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

As I said, it's not necessary because wcsncpy copies the NUL termination if it's counted in buflen (which is the case because buflen > r1 == len(buf_without_NUL). And wcsncpy just fills the remaining chars with NUL chars:

If, after copying the terminating null wide character from src, count is not reached, additional null wide characters are written to dest until the total of count characters have been written.

So we'll anyway have a NUL termination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants