From: VMware, Inc <> Date: Mon, 20 Sep 2010 18:03:04 +0000 (-0700) Subject: Don't crash tools if backdoor is disabled. X-Git-Tag: stable-8.6.0~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f7ca197a633b06fa90fe10412dce41859f74dc58;p=thirdparty%2Fopen-vm-tools.git Don't crash tools if backdoor is disabled. Four fixes: . the provider list is empty when we don't detect the backdoor, so need to check for NULL when cleaning it up. . check if backdoor is available before trying to execute a command when invoking "vmtoolsd --cmd". . unity plugin shouldn't initialize itself if rpc channel is not available. . ditto for dnd. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/services/plugins/dndcp/dndcp.cpp b/open-vm-tools/services/plugins/dndcp/dndcp.cpp index 346de25e6..b72191154 100644 --- a/open-vm-tools/services/plugins/dndcp/dndcp.cpp +++ b/open-vm-tools/services/plugins/dndcp/dndcp.cpp @@ -173,29 +173,33 @@ ToolsOnLoad(ToolsAppCtx *ctx) NULL }; - ToolsPluginSignalCb sigs[] = { - { TOOLS_CORE_SIG_CAPABILITIES, (void *) DnDCPCapabilities, NULL }, - { TOOLS_CORE_SIG_RESET, (void *) DnDCPReset, NULL }, - { TOOLS_CORE_SIG_SET_OPTION, (void *) DnDCPSetOption, NULL }, - { TOOLS_CORE_SIG_SHUTDOWN, (void *) DnDCPShutdown, NULL } - }; - - ToolsAppReg regs[] = { - { TOOLS_APP_SIGNALS, VMTools_WrapArray(sigs, sizeof *sigs, ARRAYSIZE(sigs)) } - }; - - /* - * DnD/CP Initialization here. - */ - - CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance(); - if (p) { - p->Init(ctx); - p->PointerInit(); + if (ctx->rpc != NULL) { + ToolsPluginSignalCb sigs[] = { + { TOOLS_CORE_SIG_CAPABILITIES, (void *) DnDCPCapabilities, NULL }, + { TOOLS_CORE_SIG_RESET, (void *) DnDCPReset, NULL }, + { TOOLS_CORE_SIG_SET_OPTION, (void *) DnDCPSetOption, NULL }, + { TOOLS_CORE_SIG_SHUTDOWN, (void *) DnDCPShutdown, NULL } + }; + + ToolsAppReg regs[] = { + { TOOLS_APP_SIGNALS, VMTools_WrapArray(sigs, sizeof *sigs, ARRAYSIZE(sigs)) } + }; + + /* + * DnD/CP Initialization here. + */ + + CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance(); + if (p) { + p->Init(ctx); + p->PointerInit(); + } + + regData.regs = VMTools_WrapArray(regs, sizeof *regs, ARRAYSIZE(regs)); + return ®Data; } - regData.regs = VMTools_WrapArray(regs, sizeof *regs, ARRAYSIZE(regs)); - return ®Data; + return NULL; } } diff --git a/open-vm-tools/services/plugins/unity/unityPluginEntry.cpp b/open-vm-tools/services/plugins/unity/unityPluginEntry.cpp index 0c7d3cd4a..5806fd015 100644 --- a/open-vm-tools/services/plugins/unity/unityPluginEntry.cpp +++ b/open-vm-tools/services/plugins/unity/unityPluginEntry.cpp @@ -175,36 +175,40 @@ ToolsOnLoad(ToolsAppCtx *ctx) NULL }; - ToolsPluginSignalCb sigs[] = { - { TOOLS_CORE_SIG_RESET, (void *) UnityPluginReset, ®Data }, - { TOOLS_CORE_SIG_SHUTDOWN, (void *) UnityPluginShutdown, ®Data }, - { TOOLS_CORE_SIG_CAPABILITIES, (void *) UnityPluginCapabilities, ®Data }, - { TOOLS_CORE_SIG_SET_OPTION, (void *) UnityPluginSetOption, ®Data }, - }; + if (ctx->rpc != NULL) { + ToolsPluginSignalCb sigs[] = { + { TOOLS_CORE_SIG_RESET, (void *) UnityPluginReset, ®Data }, + { TOOLS_CORE_SIG_SHUTDOWN, (void *) UnityPluginShutdown, ®Data }, + { TOOLS_CORE_SIG_CAPABILITIES, (void *) UnityPluginCapabilities, ®Data }, + { TOOLS_CORE_SIG_SET_OPTION, (void *) UnityPluginSetOption, ®Data }, + }; - ToolsPlugin *pluginInstance = NULL; + ToolsPlugin *pluginInstance = NULL; #if WIN32 - pluginInstance = new UnityPluginWin32(ctx); + pluginInstance = new UnityPluginWin32(ctx); #else // Linux - pluginInstance = new UnityPlugin(ctx); + pluginInstance = new UnityPlugin(ctx); #endif - if (!pluginInstance) { - // There's nothing we can do if we can't construct the plugin instance - return NULL; - } - regData._private = pluginInstance; + if (!pluginInstance) { + // There's nothing we can do if we can't construct the plugin instance + return NULL; + } + regData._private = pluginInstance; - std::vector rpcs = pluginInstance->GetRpcCallbackList(); + std::vector rpcs = pluginInstance->GetRpcCallbackList(); - ToolsAppReg regs[] = { - { TOOLS_APP_GUESTRPC, VMTools_WrapArray(&rpcs[0], sizeof rpcs[0], rpcs.size()) }, - { TOOLS_APP_SIGNALS, VMTools_WrapArray(sigs, sizeof *sigs, ARRAYSIZE(sigs)) } - }; + ToolsAppReg regs[] = { + { TOOLS_APP_GUESTRPC, VMTools_WrapArray(&rpcs[0], sizeof rpcs[0], rpcs.size()) }, + { TOOLS_APP_SIGNALS, VMTools_WrapArray(sigs, sizeof *sigs, ARRAYSIZE(sigs)) } + }; - regData.regs = VMTools_WrapArray(regs, sizeof *regs, ARRAYSIZE(regs)); + regData.regs = VMTools_WrapArray(regs, sizeof *regs, ARRAYSIZE(regs)); + + return ®Data; + } - return ®Data; + return NULL; } diff --git a/open-vm-tools/services/vmtoolsd/cmdLine.c b/open-vm-tools/services/vmtoolsd/cmdLine.c index 655579c5e..ee24e3aab 100644 --- a/open-vm-tools/services/vmtoolsd/cmdLine.c +++ b/open-vm-tools/services/vmtoolsd/cmdLine.c @@ -37,6 +37,7 @@ #include "conf.h" #include "rpcout.h" #include "str.h" +#include "vmcheck.h" #include "vmtoolsd_version.h" #include "vmware/tools/utils.h" #include "vmware/tools/i18n.h" @@ -60,19 +61,26 @@ ToolsCoreRunCommand(const gchar *option, gpointer data, GError **error) { - char *result = NULL; - Bool status = FALSE; +#if defined(_WIN32) + VMTools_AttachConsole(); +#endif + if (VmCheck_IsVirtualWorld()) { + char *result = NULL; + Bool status = FALSE; - status = RpcOut_sendOne(&result, NULL, "%s", value); + status = RpcOut_sendOne(&result, NULL, "%s", value); - if (!status) { - g_printerr("%s\n", result ? result : "NULL"); - } else { - g_print("%s\n", result); - } + if (!status) { + g_printerr("%s\n", result ? result : "NULL"); + } else { + g_print("%s\n", result); + } - vm_free(result); - exit(status ? 0 : 1); + vm_free(result); + exit(status ? 0 : 1); + } + g_printerr(SU_(cmdline.rpcerror, "Unable to send command to VMware hypervisor.\n")); + exit(1); } diff --git a/open-vm-tools/services/vmtoolsd/pluginMgr.c b/open-vm-tools/services/vmtoolsd/pluginMgr.c index 7b2a0aeca..68c68ca8e 100644 --- a/open-vm-tools/services/vmtoolsd/pluginMgr.c +++ b/open-vm-tools/services/vmtoolsd/pluginMgr.c @@ -736,7 +736,7 @@ ToolsCore_UnloadPlugins(ToolsServiceState *state) * Stop all app providers, and free the memory we allocated for the two * internal app providers. */ - for (i = 0; i < state->providers->len; i++) { + for (i = 0; state->providers != NULL && i < state->providers->len; i++) { ToolsAppProviderReg *preg = &g_array_index(state->providers, ToolsAppProviderReg, i); @@ -774,8 +774,10 @@ ToolsCore_UnloadPlugins(ToolsServiceState *state) g_free(plugin); } - g_array_free(state->providers, TRUE); - state->providers = NULL; + if (state->providers != NULL) { + g_array_free(state->providers, TRUE); + state->providers = NULL; + } g_ptr_array_free(state->plugins, TRUE); state->plugins = NULL;