]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix potential integer overflow when calling g_timeout_source_new() or
authorJohn Wolfe <jwolfe@vmware.com>
Tue, 21 Dec 2021 20:48:50 +0000 (12:48 -0800)
committerJohn Wolfe <jwolfe@vmware.com>
Tue, 21 Dec 2021 20:48:50 +0000 (12:48 -0800)
g_timeout_source_new_seconds().

open-vm-tools/services/plugins/appInfo/appInfo.c
open-vm-tools/services/plugins/containerInfo/containerInfo.c
open-vm-tools/services/plugins/guestInfo/guestInfoServer.c
open-vm-tools/services/plugins/guestStore/guestStorePlugin.c
open-vm-tools/services/plugins/vmbackup/stateMachine.c

index d6be49def55f8d8d5886532a20e280093af195b4..0757ace8a1ba7c2d193beea78fd0827f008c03df 100644 (file)
@@ -505,7 +505,7 @@ TweakGatherLoop(ToolsAppCtx *ctx,  // IN
                                               CONFNAME_APPINFO_POLLINTERVAL,
                                               APP_INFO_POLL_INTERVAL);
 
-      if (pollInterval < 0) {
+      if (pollInterval < 0 || pollInterval > (G_MAXINT / 1000)) {
          g_warning("%s: Invalid poll interval %d. Using default %us.\n",
                    __FUNCTION__, pollInterval, APP_INFO_POLL_INTERVAL);
          pollInterval = APP_INFO_POLL_INTERVAL;
index a4a960b698988b6459c9b1fb10b0b120877df7fa..0c6d5d01b0be33e555d6bdf13679434003df559f 100644 (file)
@@ -753,7 +753,7 @@ TweakGatherLoop(ToolsAppCtx *ctx,   // IN
                                   CONFNAME_CONTAINERINFO_POLLINTERVAL,
                                   CONTAINERINFO_DEFAULT_POLL_INTERVAL);
 
-      if (pollInterval < 0) {
+      if (pollInterval < 0 || pollInterval > (G_MAXINT / 1000)) {
          g_warning("%s: Invalid poll interval %d. Using default %us.\n",
                    __FUNCTION__, pollInterval,
                    CONTAINERINFO_DEFAULT_POLL_INTERVAL);
index d483fd2bd5cd8f58e3eb8d2fc7aa7f6f3e43ae5d..edd63219ca6aa8677a2cf77d0981e6abc703e023 100644 (file)
@@ -1986,29 +1986,20 @@ TweakGatherLoop(ToolsAppCtx *ctx,
    gint pollInterval = 0;
 
    if (enable) {
-      pollInterval = defInterval * 1000;
-
       /*
        * Check the config registry for custom poll interval,
        * converting from seconds to milliseconds.
        */
-      if (g_key_file_has_key(ctx->config, CONFGROUPNAME_GUESTINFO,
-                             cfgKey, NULL)) {
-         GError *gError = NULL;
-
-         pollInterval = g_key_file_get_integer(ctx->config,
-                                               CONFGROUPNAME_GUESTINFO,
-                                               cfgKey, &gError);
-         pollInterval *= 1000;
-
-         if (pollInterval < 0 || gError) {
-            g_warning("Invalid %s.%s value. Using default %us.\n",
-                      CONFGROUPNAME_GUESTINFO, cfgKey, defInterval);
-            pollInterval = defInterval * 1000;
-         }
-
-         g_clear_error(&gError);
+      pollInterval = VMTools_ConfigGetInteger(ctx->config,
+                                              CONFGROUPNAME_GUESTINFO,
+                                              cfgKey, defInterval);
+      if (pollInterval < 0 || pollInterval > (G_MAXINT / 1000)) {
+         g_warning("Invalid %s.%s value. Using default %us.\n",
+                   CONFGROUPNAME_GUESTINFO, cfgKey, defInterval);
+         pollInterval = defInterval;
       }
+
+      pollInterval *= 1000;
    }
 
    if (*timeoutSource != NULL) {
index 9b6fb80a6a8be156740b662962b2a3ae7c5df62a..c7da4481e58c819b75ed75e15b14c0dc19e9289f 100644 (file)
@@ -1390,7 +1390,7 @@ StartCurrentClientConnRecvTimeout(void)
 
    clientRecvTimeout = GUESTSTORE_CONFIG_GET_INT("clientRecvTimeout",
       DEFAULT_CLIENT_RECV_TIMEOUT);
-   if (clientRecvTimeout <= 0) {
+   if (clientRecvTimeout <= 0 || clientRecvTimeout > (G_MAXINT / 1000)) {
       g_warning("Invalid clientRecvTimeout (%d); Using default (%d).\n",
                 clientRecvTimeout, DEFAULT_CLIENT_RECV_TIMEOUT);
       clientRecvTimeout = DEFAULT_CLIENT_RECV_TIMEOUT;
@@ -2282,7 +2282,8 @@ VmxConnectCb(AsyncSocket *asock,  // IN
 
    theVmxConn->connTimeout = GUESTSTORE_CONFIG_GET_INT("connTimeout",
       GUESTSTORE_DEFAULT_CONN_TIMEOUT);
-   if (theVmxConn->connTimeout <= 0) {
+   if (theVmxConn->connTimeout <= 0 ||
+       theVmxConn->connTimeout > (G_MAXINT / 1000)) {
       g_warning("Invalid connTimeout (%d); Using default (%d).\n",
                 theVmxConn->connTimeout, GUESTSTORE_DEFAULT_CONN_TIMEOUT);
       theVmxConn->connTimeout = GUESTSTORE_DEFAULT_CONN_TIMEOUT;
index 473419bfa5be2875dfd71bfbd7c4d8dc014968ad..99f52582430dd8619603af98eec1ccd2ff87f547 100644 (file)
@@ -114,6 +114,31 @@ static Bool
 VmBackupEnableCompleteWait(void);
 
 
+/**
+ * Returns the configured timeout value.
+ *
+ * @param[in]  config   Config file to read from.
+ * @param[in]  defValue Default value if the timeout key is not found or error.
+ *
+ * @return value of the timeout key if read successfully,
+ *         defValue otherwise.
+ */
+
+static gint
+VmBackupGetTimeout(GKeyFile *config,
+                   const gint defValue)
+{
+   gint timeout = VMBACKUP_CONFIG_GET_INT(config, "timeout", defValue);
+   if (timeout < 0 || timeout > (G_MAXINT / 1000)) {
+      g_warning("Invalid timeout %d. Using default %us.",
+                timeout, defValue);
+      timeout = defValue;
+   }
+
+   return timeout;
+}
+
+
 /**
  * Returns a string representation of the given state machine state.
  *
@@ -1081,8 +1106,8 @@ VmBackupStartCommon(RpcInData *data,
     * See bug 506106.
     */
    if (gBackupState->timeout == 0) {
-      gBackupState->timeout = VMBACKUP_CONFIG_GET_INT(ctx->config, "timeout",
-                                       GUEST_QUIESCE_DEFAULT_TIMEOUT_IN_SEC);
+      gBackupState->timeout = VmBackupGetTimeout(ctx->config,
+                                 GUEST_QUIESCE_DEFAULT_TIMEOUT_IN_SEC);
    }
 
    /* Treat "0" as no timeout. */
@@ -1167,8 +1192,7 @@ VmBackupStart(RpcInData *data)
       gBackupState->scriptArg = VMBACKUP_CONFIG_GET_STR(ctx->config,
                                                         "scriptArg",
                                                         NULL);
-      gBackupState->timeout = VMBACKUP_CONFIG_GET_INT(ctx->config,
-                                                      "timeout", 0);
+      gBackupState->timeout = VmBackupGetTimeout(ctx->config, 0);
       gBackupState->vssUseDefault = VMBACKUP_CONFIG_GET_BOOL(ctx->config,
                                                              "vssUseDefault",
                                                              TRUE);