]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/misc: Do not constrain the OS name string
authorVMware, Inc <>
Mon, 22 Aug 2011 20:12:14 +0000 (13:12 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 22 Aug 2011 20:12:14 +0000 (13:12 -0700)
The Hostinfo API for obtaining the OS name constrains the name
of the OS. These strings are highly variable in length and may
grow unexpectedly. Refactor the API to not care about the length
and fixup the call sites.

In a future change the internals of lib/misc will be overhauled
to also not care about the size. For now the (internal) size will
be inflated to more than large enough (512).

Another future change will remove any limitations found within the
tools code.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/include/hostinfo.h
open-vm-tools/lib/misc/hostinfo.c
open-vm-tools/lib/misc/hostinfoInt.h
open-vm-tools/services/plugins/guestInfo/guestInfoServer.c
open-vm-tools/services/plugins/vix/vixTools.c

index 963d1e5785fbf7c4bfa43034a45f7d072b63848c..50d9ff54816348e164d34d3de56319b6f210a7ed 100644 (file)
@@ -70,10 +70,8 @@ extern int Hostinfo_OSVersion(unsigned int i);
 extern int Hostinfo_GetSystemBitness(void);
 extern const char *Hostinfo_OSVersionString(void);
 
-extern Bool Hostinfo_GetOSName(uint32 outBufFullLen,
-                               uint32 outBufLen,
-                               char *osNameFull,
-                               char *osName);
+extern char *Hostinfo_GetOSName(void);
+extern char *Hostinfo_GetOSGuestString(void);
 
 extern Bool Hostinfo_OSIsSMP(void);
 #if defined(_WIN32)
index 0bb96612fdd6079eb0545e0e52c89f646dd8a2ac..d09f9914d1396ec147f048aebdfbadbb279ae476 100644 (file)
@@ -256,11 +256,9 @@ Hostinfo_GetCpuid(HostinfoCpuIdInfo *info) // OUT
  *
  * Hostinfo_GetOSName --
  *
- *      Query the operating system and build a pair of strings to identify it.
- *      The two strings are osName and osNameFull.  Short osName strings are
- *      the same as you'd see in a VM's .vmx file.
+ *      Query the operating system and build a string to identify it.
  *
- *      The long names are a bit more descriptive:
+ *      Examples:
  *         Windows: <OS NAME> <SERVICE PACK> (BUILD <BUILD_NUMBER>)
  *         example: Windows XP Professional Service Pack 2 (Build 2600)
  *
@@ -268,31 +266,62 @@ Hostinfo_GetCpuid(HostinfoCpuIdInfo *info) // OUT
  *         example: Linux 2.4.18-3 Red Hat Linux release 7.3 (Valhalla)
  *
  * Return value:
- *      Returns TRUE on success and FALSE on failure.
- *      Returns the guest's full OS name (osFullName)
- *      Returns the guest's OS name in the same format as .vmx file (osName)
+ *      NULL  Unable to obtain the OS name.
+ *     !NULL  The OS name. The caller is responsible for freeing it.
  *
  * Side effects:
- *      None
+ *      Memory is allocated.
  *
  *-----------------------------------------------------------------------------
  */
 
-Bool
-Hostinfo_GetOSName(uint32 outBufFullLen,  // IN: length of osFullName buffer
-                   uint32 outBufLen,      // IN: length of osName buffer
-                   char *osFullName,      // OUT: Full OS name
-                   char *osName)          // OUT: OS name
+char *
+Hostinfo_GetOSName(void)
 {
-   Bool retval;
+   char *name;
+   Bool data = HostinfoOSNameCacheValid ? TRUE : HostinfoOSData();
+
+   if (data) {
+       name = Util_SafeStrdup(HostinfoCachedOSFullName);
+   } else {
+      name = NULL;
+   }
+
+   return name;
+}
+
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Hostinfo_GetOSGuestString --
+ *
+ *      Query the operating system and build a string to identify it. The
+ *      returned string is the same as you'd see in a VM's .vmx file.
+ *
+ * Return value:
+ *      NULL  Unable to obtain the OS name.
+ *     !NULL  The OS name. The caller is responsible for freeing it.
+ *
+ * Side effects:
+ *      Memory is allocated.
+ *
+ *-----------------------------------------------------------------------------
+ */
 
-   retval = HostinfoOSNameCacheValid ? TRUE : HostinfoOSData();
+char *
+Hostinfo_GetOSGuestString(void)
+{
+   char *name;
+   Bool data = HostinfoOSNameCacheValid ? TRUE : HostinfoOSData();
 
-   if (retval) {
-       Str_Strcpy(osFullName, HostinfoCachedOSFullName, outBufFullLen);
-       Str_Strcpy(osName, HostinfoCachedOSName, outBufLen);
+   if (data) {
+       name = Util_SafeStrdup(HostinfoCachedOSName);
+   } else {
+      name = NULL;
    }
 
-   return retval;
+   return name;
 }
 
index a761536020dde30cf3d2bca9134d23aab9482fbb..93e674504c5ee52f06583b73d39e125df81671ac 100644 (file)
@@ -26,8 +26,8 @@
 #define _HOSTINFOINT_H_
 
 
-#define MAX_OS_NAME_LEN 64
-#define MAX_OS_FULLNAME_LEN 192
+#define MAX_OS_NAME_LEN 128
+#define MAX_OS_FULLNAME_LEN 512
 
 
 /*
index 0baa48eae0775058fc3fa47d27c1cd78ca3af779..cf52b7f364dad7eebb95c6ab4f0c64612e89aac4 100644 (file)
@@ -233,8 +233,7 @@ static gboolean
 GuestInfoGather(gpointer data)
 {
    char name[GUESTINFO_MAX_VALUE_SIZE];
-   char osNameFull[GUESTINFO_MAX_VALUE_SIZE];
-   char osName[GUESTINFO_MAX_VALUE_SIZE];
+   char *osString = NULL;
    gboolean disableQueryDiskInfo;
    NicInfoV3 *nicInfo = NULL;
    GuestDiskInfo *diskInfo = NULL;
@@ -257,17 +256,25 @@ GuestInfoGather(gpointer data)
    }
 
    /* Gather all the relevant guest information. */
-   if (!Hostinfo_GetOSName(sizeof osNameFull, sizeof osName, osNameFull,
-                           osName)) {
+   osString = Hostinfo_GetOSName();
+   if (osString == NULL) {
       g_warning("Failed to get OS info.\n");
    } else {
-      if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME_FULL, osNameFull)) {
+      if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME_FULL, osString)) {
          g_warning("Failed to update VMDB\n");
       }
-      if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME, osName)) {
+   }
+   free(osString);
+
+   osString = Hostinfo_GetOSGuestString();
+   if (osString == NULL) {
+      g_warning("Failed to get OS info.\n");
+   } else {
+      if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME, osString)) {
          g_warning("Failed to update VMDB\n");
       }
    }
+   free(osString);
 
    disableQueryDiskInfo =
       g_key_file_get_boolean(ctx->config, CONFGROUPNAME_GUESTINFO,
index ccf792808a315feec897e9232603cf0877f8405e..0ab9b43937d1bcf6b245009127bc79a40f76ec1c 100644 (file)
@@ -1988,8 +1988,8 @@ VixTools_GetToolsPropertiesImpl(GKeyFile *confDictRef,            // IN
    const char *powerOnScript = NULL;
    const char *resumeScript = NULL;
    const char *suspendScript = NULL;
-   char osNameFull[GUESTINFO_MAX_VALUE_SIZE];
-   char osName[GUESTINFO_MAX_VALUE_SIZE];
+   char *osName = NULL;
+   char *osNameFull = NULL;
    Bool foundHostName;
    char *tempDir = NULL;
    int wordSize = 32;
@@ -2023,11 +2023,17 @@ VixTools_GetToolsPropertiesImpl(GKeyFile *confDictRef,            // IN
 #else
    osFamily = GUEST_OS_FAMILY_LINUX;
 #endif
-   if (!(Hostinfo_GetOSName(sizeof osNameFull, sizeof osName, osNameFull,
-                            osName))) {
-      osNameFull[0] = 0;
-      osName[0] = 0;
+
+   osNameFull = Hostinfo_GetOSName();
+   if (osNameFull == NULL) {
+      osNameFull = Util_SafeStrdup("");
+   }
+
+   osName = Hostinfo_GetOSGuestString();
+   if (osName == NULL) {
+      osName = Util_SafeStrdup("");
    }
+
    wordSize = Hostinfo_GetSystemBitness();
    if (wordSize <= 0) {
       wordSize = 32;
@@ -2180,6 +2186,8 @@ abort:
    free(guestName);
    free(serializedBuffer);
    free(tempDir);
+   free(osName);
+   free(osNameFull);
 #else
    /*
     * FreeBSD.  Return an empty serialized property list.
@@ -2219,7 +2227,7 @@ abort:
    VixPropertyList_RemoveAllWithoutHandles(&propList);
    free(serializedBuffer);
 #endif // __FreeBSD__
-   
+
    return err;
 } // VixTools_GetToolsPropertiesImpl