尽快推进:收紧PythonPlugin禁用边界

结论:对齐LinuxCNC src/emc/pythonplugin/python_plugin.cc initialize() 负状态语义,WASM安全shim在Python不可用时返回PLUGIN_PYTHON_NOT_INITIALIZED并保持负状态短路;未实现Python/remap执行,未扩展smoke parser。
This commit is contained in:
cnc
2026-06-05 07:50:13 +08:00
parent 6a2f63c894
commit 6d99ca67a9
2 changed files with 31 additions and 3 deletions

View File

@@ -42,8 +42,7 @@ int PythonPlugin::configure(const char *iniFilename, const char *section) {
} }
std::fclose(file); std::fclose(file);
status = PLUGIN_OK; return initialize();
return status;
} }
bool PythonPlugin::is_callable(const char *, const char *) { bool PythonPlugin::is_callable(const char *, const char *) {
@@ -86,6 +85,10 @@ int PythonPlugin::call_method(boost::python::object, boost::python::object &retv
} }
int PythonPlugin::initialize() { int PythonPlugin::initialize() {
status = PLUGIN_OK; // LinuxCNC source basis: src/emc/pythonplugin/python_plugin.cc sets
// PLUGIN_PYTHON_NOT_INITIALIZED when initialize() runs without an active
// Python runtime. Browser-safe probes keep Python execution disabled.
error_msg = "python disabled in wasm-safe probe";
status = PLUGIN_PYTHON_NOT_INITIALIZED;
return status; return status;
} }

View File

@@ -1,5 +1,7 @@
#include "pythonplugin/python_plugin.hh" #include "pythonplugin/python_plugin.hh"
#include <cstdio>
// LinuxCNC source basis: src/emc/pythonplugin/python_plugin.cc and // LinuxCNC source basis: src/emc/pythonplugin/python_plugin.cc and
// python_plugin.hh define the PythonPlugin API exercised by this link probe. // python_plugin.hh define the PythonPlugin API exercised by this link probe.
int main() { int main() {
@@ -26,6 +28,29 @@ int main() {
if (plugin->run_string("noop", retval, false) != PLUGIN_OK) { if (plugin->run_string("noop", retval, false) != PLUGIN_OK) {
return 3; return 3;
} }
const char *ini = "/tmp/cnc_sim_python_plugin_probe.ini";
{
FILE *file = std::fopen(ini, "w");
if (!file) {
return 16;
}
std::fputs("[PYTHON]\n", file);
std::fclose(file);
}
if (plugin->configure(ini, "PYTHON") != PLUGIN_PYTHON_NOT_INITIALIZED) {
std::remove(ini);
return 17;
}
std::remove(ini);
if (plugin->call(nullptr, "noop", boost::python::object(), boost::python::object(), retval) != PLUGIN_PYTHON_NOT_INITIALIZED) {
return 18;
}
if (plugin->call_method(boost::python::object(), retval) != PLUGIN_PYTHON_NOT_INITIALIZED) {
return 19;
}
if (plugin->run_string("noop", retval, false) != PLUGIN_OK) {
return 20;
}
if (plugin->call(nullptr, nullptr, boost::python::object(), boost::python::object(), retval) != PLUGIN_NO_CALLABLE) { if (plugin->call(nullptr, nullptr, boost::python::object(), boost::python::object(), retval) != PLUGIN_NO_CALLABLE) {
return 8; return 8;
} }