]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix disagreement on buffer sizes in guest info plugin.
authorVMware, Inc <>
Tue, 29 Mar 2011 18:50:34 +0000 (11:50 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 29 Mar 2011 18:50:34 +0000 (11:50 -0700)
The info cache only allowed 100 bytes (MAX_VALUE_LEN), while the buffer
that held the host name allowed 255 (to follow what the man page says).
Make both agree.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/services/plugins/guestInfo/guestInfoServer.c

index 1a1a8c5bfc21ea25614ad20f124aaf4d9cbd3dd3..9037257543587ad1b2e5e7cabe45b1a8a4e179ed 100644 (file)
@@ -66,6 +66,20 @@ VM_EMBED_VERSION(VMTOOLSD_VERSION_STRING);
 #endif
 
 
+/**
+ * Upper bound for value sizes, based on gethostname(2):
+ *
+ *    SUS2 guarantees that "Host names are limited to 255 bytes".
+ *
+ * We can't modify MAX_VALUE_LEN since it's used in wire-level definitions
+ * (such as PartitionEntry).
+ */
+#define GUESTINFO_MAX_VALUE_SIZE    256
+
+MY_ASSERTS(GI_SIZE_ASSERTS,
+           ASSERT_ON_COMPILE(GUESTINFO_MAX_VALUE_SIZE >= MAX_VALUE_LEN);
+)
+
 /**
  * Default poll interval is 30s (in milliseconds).
  */
@@ -78,7 +92,8 @@ VM_EMBED_VERSION(VMTOOLSD_VERSION_STRING);
  */
 
 typedef struct _GuestInfoCache{
-   char value[INFO_MAX][MAX_VALUE_LEN]; /* Stores values of all key-value pairs. */
+   /* Stores values of all key-value pairs. */
+   char value[INFO_MAX][GUESTINFO_MAX_VALUE_SIZE];
    NicInfoV3     *nicInfo;
    GuestDiskInfo *diskInfo;
 } GuestInfoCache;
@@ -227,9 +242,9 @@ GuestInfoVMSupport(RpcInData *data)
 static gboolean
 GuestInfoGather(gpointer data)
 {
-   char name[255];
-   char osNameFull[MAX_VALUE_LEN];
-   char osName[MAX_VALUE_LEN];
+   char name[GUESTINFO_MAX_VALUE_SIZE];
+   char osNameFull[GUESTINFO_MAX_VALUE_SIZE];
+   char osName[GUESTINFO_MAX_VALUE_SIZE];
    gboolean disableQueryDiskInfo;
    NicInfoV3 *nicInfo = NULL;
    GuestDiskInfo *diskInfo = NULL;
@@ -458,7 +473,9 @@ GuestInfoUpdateVmdb(ToolsAppCtx *ctx,       // IN: Application context
       }
 
       /* Update the value in the cache as well. */
-      Str_Strcpy(gInfoCache.value[infoType], (char *)info, MAX_VALUE_LEN);
+      Str_Strcpy(gInfoCache.value[infoType],
+                 (char *)info,
+                 sizeof gInfoCache.value[infoType]);
       break;
 
    case INFO_IPADDRESS: