]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Adding null check for results passed to log function.
authorJohn Wolfe <jwolfe@vmware.com>
Fri, 11 Sep 2020 19:11:03 +0000 (12:11 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Fri, 11 Sep 2020 19:11:03 +0000 (12:11 -0700)
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.

open-vm-tools/lib/include/vmware/tools/log.h
open-vm-tools/services/plugins/guestInfo/guestInfoServer.c
open-vm-tools/services/plugins/vmbackup/stateMachine.c
open-vm-tools/services/vmtoolsd/toolsRpc.c
open-vm-tools/toolbox/toolboxcmd-info.c
open-vm-tools/toolbox/toolboxcmd-shrink.c
open-vm-tools/toolbox/toolboxcmd-time.c

index 222ed1658b8cdbb77fbbf617327caf4cbe13c473..c810b6266332acd3917a8bf2cdf35a040cbac647 100644 (file)
@@ -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
 
index da0b95e68bc2f5aad3ff9f205a0be554aed968cf..c1ab69629056017aafe8a7e7aa1b976a8b6dc4a3 100644 (file)
@@ -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);
index d041eade88fee657dbcb70b8ec2b9c875ce525f8..a443b85e6752e92bab9b41cdd0a72a0367063b4e 100644 (file)
@@ -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);
index 9ed6d47bfad0321f06b06445cdb81b3b2085cde7..d5a115b91ec12b63d66a58f570807a1989265943 100644 (file)
@@ -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);
index c7408d1fe71bb4c8a7863a0f3a23d8c3cd841b98..ef32543b99b4403760e19d794be68c3c0a576782 100644 (file)
@@ -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);
    }
index d23442467c845e254dfc6d691740139bbfacdeef..9597d7bf4ea69014adc6d5617d5bc0717633febb 100644 (file)
@@ -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;
    }
 
index 6e95b6bd5d9284feacfaa1deace3968bafba0783..673abd1753eafac58e1d2749a634af69e0688b88 100644 (file)
@@ -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;
    }