check returned value of PyUnicode_AsUTF8() before passing to a std::string to avoid possible segfaults

This commit is contained in:
wmayer
2019-12-09 12:23:58 +01:00
parent 8516c6fbe3
commit fd741e4338

View File

@@ -503,8 +503,13 @@ App::any pyObjectToAny(Py::Object value, bool check) {
return App::any(std::string(PyString_AsString(s)));
}
#else
else if (PyUnicode_Check(pyvalue))
return App::any(std::string(PyUnicode_AsUTF8(pyvalue)));
else if (PyUnicode_Check(pyvalue)) {
const char* value = PyUnicode_AsUTF8(pyvalue);
if (!value) {
FC_THROWM(Base::ValueError, "Invalid unicode string");
}
return App::any(std::string(value));
}
#endif
else {
return App::any(pyObjectWrap(pyvalue));