do some security checks to make sure Py::Module is valid

This commit is contained in:
wmayer
2019-06-03 17:57:52 +02:00
parent 9660b1fb1e
commit 85fddfc54a
3 changed files with 20 additions and 2 deletions

View File

@@ -1038,6 +1038,10 @@ PyObject* Application::sAddCommand(PyObject * /*self*/, PyObject *args)
try {
Base::PyGILStateLocker lock;
Py::Module mod(PyImport_ImportModule("inspect"), true);
if (mod.isNull()) {
PyErr_SetString(PyExc_ImportError, "Cannot load inspect module");
return 0;
}
Py::Callable inspect(mod.getAttr("stack"));
Py::Tuple args;
Py::List list(inspect.apply(args));

View File

@@ -1504,6 +1504,8 @@ MeshObject* MeshObject::createSphere(float radius, int sampling)
Base::PyGILStateLocker lock;
try {
Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true);
if (module.isNull())
return 0;
Py::Dict dict = module.getDict();
Py::Callable call(dict.getItem("Sphere"));
Py::Tuple args(2);
@@ -1529,6 +1531,8 @@ MeshObject* MeshObject::createEllipsoid(float radius1, float radius2, int sampli
Base::PyGILStateLocker lock;
try {
Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true);
if (module.isNull())
return 0;
Py::Dict dict = module.getDict();
Py::Callable call(dict.getItem("Ellipsoid"));
Py::Tuple args(3);
@@ -1555,6 +1559,8 @@ MeshObject* MeshObject::createCylinder(float radius, float length, int closed, f
Base::PyGILStateLocker lock;
try {
Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true);
if (module.isNull())
return 0;
Py::Dict dict = module.getDict();
Py::Callable call(dict.getItem("Cylinder"));
Py::Tuple args(5);
@@ -1585,6 +1591,8 @@ MeshObject* MeshObject::createCone(float radius1, float radius2, float len, int
Base::PyGILStateLocker lock;
try {
Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true);
if (module.isNull())
return 0;
Py::Dict dict = module.getDict();
Py::Callable call(dict.getItem("Cone"));
Py::Tuple args(6);
@@ -1616,6 +1624,8 @@ MeshObject* MeshObject::createTorus(float radius1, float radius2, int sampling)
Base::PyGILStateLocker lock;
try {
Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true);
if (module.isNull())
return 0;
Py::Dict dict = module.getDict();
Py::Callable call(dict.getItem("Toroid"));
Py::Tuple args(3);
@@ -1642,6 +1652,8 @@ MeshObject* MeshObject::createCube(float length, float width, float height)
Base::PyGILStateLocker lock;
try {
Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true);
if (module.isNull())
return 0;
Py::Dict dict = module.getDict();
Py::Callable call(dict.getItem("Cube"));
Py::Tuple args(3);
@@ -1664,6 +1676,8 @@ MeshObject* MeshObject::createCube(float length, float width, float height, floa
Base::PyGILStateLocker lock;
try {
Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true);
if (module.isNull())
return 0;
Py::Dict dict = module.getDict();
Py::Callable call(dict.getItem("FineCube"));
Py::Tuple args(4);

View File

@@ -262,7 +262,7 @@ PyObject* AttachEnginePy::getModeInfo(PyObject* args)
#endif
try {
Py::Module module(PyImport_ImportModule("PartGui"),true);
if (!module.hasAttr("AttachEngineResources")) {
if (module.isNull() || !module.hasAttr("AttachEngineResources")) {
// in v0.14+, the GUI module can be loaded in console mode (but doesn't have all its document methods)
throw Py::RuntimeError("Gui is not up");//DeepSOIC: wanted to throw ImportError here, but it's not defined, so I don't know...
}
@@ -357,7 +357,7 @@ PyObject* AttachEnginePy::getRefTypeInfo(PyObject* args)
try {
Py::Module module(PyImport_ImportModule("PartGui"),true);
if (!module.hasAttr("AttachEngineResources")) {
if (module.isNull() || !module.hasAttr("AttachEngineResources")) {
// in v0.14+, the GUI module can be loaded in console mode (but doesn't have all its document methods)
throw Py::RuntimeError("Gui is not up");//DeepSOIC: wanted to throw ImportError here, but it's not defined, so I don't know...
}