Skip to content

Segfault from py::str() #1704

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
davidhewitt opened this issue Feb 22, 2019 · 0 comments · Fixed by #2290
Closed

Segfault from py::str() #1704

davidhewitt opened this issue Feb 22, 2019 · 0 comments · Fixed by #2290

Comments

@davidhewitt
Copy link
Contributor

In the sample below:

static PyObject *raw_str(PyObject *op) {
PyObject *str_value = PyObject_Str(op);
#if PY_MAJOR_VERSION < 3
if (!str_value) throw error_already_set();
PyObject *unicode = PyUnicode_FromEncodedObject(str_value, "utf-8", nullptr);
Py_XDECREF(str_value); str_value = unicode;
#endif
return str_value;
}

I'm pretty sure the #if PY_MAJOR_VERSION < 3 and if (!str_value) throw error_already_set(); lines are the wrong way around. As it stands, on Python 3 then if the PyObject_Str() call fails then a nullptr becomes the ptr held by a py::str object, leading to possible segfaults.

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 a pull request may close this issue.

1 participant