From: John Wolfe Date: Fri, 11 Sep 2020 19:11:03 +0000 (-0700) Subject: Adding null check for results passed to log function. X-Git-Tag: stable-11.2.0~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=652aeafa2cee7893b66f73f3096077232e6dce93;p=thirdparty%2Fopen-vm-tools.git Adding null check for results passed to log function. In several files, replies/results from RPC functions can possibly be null if the function fails. This changeset adds a function-like macro which does the null checks and is applied to the replies when passed into logging functions. --- diff --git a/open-vm-tools/lib/include/vmware/tools/log.h b/open-vm-tools/lib/include/vmware/tools/log.h index 222ed1658..c810b6266 100644 --- a/open-vm-tools/lib/include/vmware/tools/log.h +++ b/open-vm-tools/lib/include/vmware/tools/log.h @@ -313,6 +313,8 @@ g_warning_inline(const gchar *fmt, #define vm_warning(fmt, ...) g_warning("%s: " fmt, FUNC, ## __VA_ARGS__) #endif // ! (windows & glib >= 2.46) +/* Checks if a string is null before it is passed in logging function */ +#define VM_SAFE_STR(string) (string != NULL ? string : "(NULL)") G_BEGIN_DECLS diff --git a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c index da0b95e68..c1ab69629 100644 --- a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c +++ b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c @@ -991,7 +991,7 @@ GuestInfoSendNicInfoXdr(ToolsAppCtx *ctx, // IN &reply, &replyLen); if (!status) { g_warning("%s: update failed: request \"%s\", reply \"%s\".\n", - __FUNCTION__, request, reply); + __FUNCTION__, request, VM_SAFE_STR(reply)); } vm_free(reply); } @@ -1052,7 +1052,7 @@ GuestInfoSendData(ToolsAppCtx *ctx, // IN status = RpcChannel_Send(ctx->rpc, message, msgLength, &reply, &replyLen); if (!status) { g_warning("%s: update failed: request \"%s\", reply \"%s\".\n", - __FUNCTION__, request, reply); + __FUNCTION__, request, VM_SAFE_STR(reply)); } vm_free(reply); @@ -1375,7 +1375,7 @@ GuestInfoSendDiskInfoV1(ToolsAppCtx *ctx, // IN } } else { g_debug("%s: RPC failed (%d) reply '%s'\n", - __FUNCTION__, status, reply ? reply : ""); + __FUNCTION__, status, VM_SAFE_STR(reply)); } vm_free(reply); diff --git a/open-vm-tools/services/plugins/vmbackup/stateMachine.c b/open-vm-tools/services/plugins/vmbackup/stateMachine.c index d041eade8..a443b85e6 100644 --- a/open-vm-tools/services/plugins/vmbackup/stateMachine.c +++ b/open-vm-tools/services/plugins/vmbackup/stateMachine.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007-2019 VMware, Inc. All rights reserved. + * Copyright (C) 2007-2020 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -48,6 +48,7 @@ #endif #include "vmware/tools/utils.h" #include "vmware/tools/vmbackup.h" +#include "vmware/tools/log.h" #include "xdrutil.h" #if !defined(__APPLE__) @@ -285,7 +286,7 @@ VmBackup_SendEventNoAbort(const char *event, NULL); } else { g_warning("Failed to send vmbackup event: %s, result: %s.\n", - msg, result); + msg, VM_SAFE_STR(result)); } vm_free(result); g_free(msg); diff --git a/open-vm-tools/services/vmtoolsd/toolsRpc.c b/open-vm-tools/services/vmtoolsd/toolsRpc.c index 9ed6d47bf..d5a115b91 100644 --- a/open-vm-tools/services/vmtoolsd/toolsRpc.c +++ b/open-vm-tools/services/vmtoolsd/toolsRpc.c @@ -280,7 +280,8 @@ ToolsCoreRpcCapReg(RpcInData *data) if (!RpcChannel_Send(state->ctx.rpc, toolsVersion, strlen(toolsVersion) + 1, &result, &resultLen)) { - g_warning("Error setting tools version: %s.\n", result); + g_warning("Error setting tools version: %s.\n", + VM_SAFE_STR(result)); } } vm_free(result); @@ -456,7 +457,8 @@ ToolsCore_SetCapabilities(RpcChannel *chan, cap->name, set ? cap->value : 0); if (!RpcChannel_Send(chan, tmp, strlen(tmp) + 1, &result, &resultLen)) { - g_warning("Error sending capability %s: %s\n", cap->name, result); + g_warning("Error sending capability %s: %s\n", cap->name, + VM_SAFE_STR(result)); } vm_free(result); g_free(tmp); @@ -474,7 +476,8 @@ ToolsCore_SetCapabilities(RpcChannel *chan, if (set) { tmp = g_strdup_printf("tools.capability.%s ", cap->name); if (!RpcChannel_Send(chan, tmp, strlen(tmp), &result, &resultLen)) { - g_warning("Error sending capability %s: %s\n", cap->name, result); + g_warning("Error sending capability %s: %s\n", cap->name, + VM_SAFE_STR(result)); } vm_free(result); g_free(tmp); @@ -501,7 +504,8 @@ ToolsCore_SetCapabilities(RpcChannel *chan, if (newcaps != NULL) { result = NULL; if (!RpcChannel_Send(chan, newcaps, strlen(newcaps) + 1, &result, &resultLen)) { - g_warning("Error sending new-style capabilities: %s\n", result); + g_warning("Error sending new-style capabilities: %s\n", + VM_SAFE_STR(result)); } vm_free(result); g_free(newcaps); diff --git a/open-vm-tools/toolbox/toolboxcmd-info.c b/open-vm-tools/toolbox/toolboxcmd-info.c index c7408d1fe..ef32543b9 100644 --- a/open-vm-tools/toolbox/toolboxcmd-info.c +++ b/open-vm-tools/toolbox/toolboxcmd-info.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2015-2019 VMware, Inc. All rights reserved. + * Copyright (C) 2015-2020 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -31,6 +31,7 @@ #include "toolboxCmdInt.h" #include "vmware/tools/i18n.h" #include "vmware/tools/utils.h" +#include "vmware/tools/log.h" #ifdef _WIN32 #include "netutil.h" #endif @@ -77,7 +78,7 @@ InfoSendNetworkXdr(GuestNicProto *message, &reply, &replyLen); if (!status) { g_warning("%s: update failed: request \"%s\", reply \"%s\".\n", - __FUNCTION__, request, reply); + __FUNCTION__, request, VM_SAFE_STR(reply)); } ToolsCmd_FreeRPC(reply); } diff --git a/open-vm-tools/toolbox/toolboxcmd-shrink.c b/open-vm-tools/toolbox/toolboxcmd-shrink.c index d23442467..9597d7bf4 100644 --- a/open-vm-tools/toolbox/toolboxcmd-shrink.c +++ b/open-vm-tools/toolbox/toolboxcmd-shrink.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2008-2019 VMware, Inc. All rights reserved. + * Copyright (C) 2008-2020 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -36,6 +36,7 @@ #include "wiper.h" #include "vmware/guestrpc/tclodefs.h" #include "vmware/tools/i18n.h" +#include "vmware/tools/log.h" #ifndef _WIN32 static void ShrinkWiperDestroy(int signal); @@ -246,8 +247,8 @@ ShrinkDiskSendRPC(void) SU_(disk.shrink.complete, "Disk shrinking complete.\n")); retVal = EXIT_SUCCESS; } else { - ToolsCmd_PrintErr(SU_(disk.shrink.error, - "Error while shrinking: %s\n"), result); + ToolsCmd_PrintErr(SU_(disk.shrink.error, "Error while shrinking: %s\n"), + VM_SAFE_STR(result)); retVal = EX_TEMPFAIL; } diff --git a/open-vm-tools/toolbox/toolboxcmd-time.c b/open-vm-tools/toolbox/toolboxcmd-time.c index 6e95b6bd5..673abd175 100644 --- a/open-vm-tools/toolbox/toolboxcmd-time.c +++ b/open-vm-tools/toolbox/toolboxcmd-time.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2008-2019 VMware, Inc. All rights reserved. + * Copyright (C) 2008-2020 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -28,6 +28,7 @@ #include "vmware/guestrpc/tclodefs.h" #include "vmware/guestrpc/timesync.h" #include "vmware/tools/i18n.h" +#include "vmware/tools/log.h" /* @@ -113,7 +114,8 @@ TimeSyncEnable(void) TimeSyncSet(TRUE, &reply, &replyLen)) { ToolsCmd_Print("%s\n", SU_(option.enabled, "Enabled")); } else { - ToolsCmd_PrintErr(SU_(error.message, "Error: %s\n"), reply); + ToolsCmd_PrintErr(SU_(error.message, "Error: %s\n"), + VM_SAFE_STR(reply)); ret = EXIT_FAILURE; } @@ -149,7 +151,8 @@ TimeSyncDisable(void) TimeSyncSet(FALSE, &reply, &replyLen)) { ToolsCmd_Print("%s\n", SU_(option.disabled, "Disabled")); } else { - ToolsCmd_PrintErr(SU_(error.message, "Error: %s\n"), reply); + ToolsCmd_PrintErr(SU_(error.message, "Error: %s\n"), + VM_SAFE_STR(reply)); ret = EXIT_FAILURE; }