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-127165: Disallow embedded NULL characters in _interpreters #127199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Nov 23, 2024

Currently, null characters in shared namespaces cause truncation of the actual string, because it's eventually passed to PyUnicode_FromString, which uses the strlen instead of the actual size. Then, things break because the string unexpectedly is not in the namespace dictionary. This fixes that by just raising if we find an embedded NULL character in _copy_string_obj_raw.

We could support embedded NULLs by storing the size alongside the name, but this is much simpler (and in practice, nobody is trying to name variables containing \x00).

Comment on lines +345 to +349
if (size != (Py_ssize_t) strlen(str))
{
PyErr_SetString(PyExc_ValueError, "found embedded NULL character");
return NULL;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (size != (Py_ssize_t) strlen(str))
{
PyErr_SetString(PyExc_ValueError, "found embedded NULL character");
return NULL;
}
if (size != (Py_ssize_t)strlen(str)) {
PyErr_SetString(PyExc_ValueError, "found embedded NULL character");
return NULL;
}

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