From: VMware, Inc <> Date: Mon, 22 Aug 2011 20:12:14 +0000 (-0700) Subject: lib/misc: Do not constrain the OS name string X-Git-Tag: 2011.08.21-471295~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=241182026adb4e47b6a28a1fda427933a8ca003e;p=thirdparty%2Fopen-vm-tools.git lib/misc: Do not constrain the OS name string 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 --- diff --git a/open-vm-tools/lib/include/hostinfo.h b/open-vm-tools/lib/include/hostinfo.h index 963d1e578..50d9ff548 100644 --- a/open-vm-tools/lib/include/hostinfo.h +++ b/open-vm-tools/lib/include/hostinfo.h @@ -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) diff --git a/open-vm-tools/lib/misc/hostinfo.c b/open-vm-tools/lib/misc/hostinfo.c index 0bb96612f..d09f9914d 100644 --- a/open-vm-tools/lib/misc/hostinfo.c +++ b/open-vm-tools/lib/misc/hostinfo.c @@ -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: (BUILD ) * 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; } diff --git a/open-vm-tools/lib/misc/hostinfoInt.h b/open-vm-tools/lib/misc/hostinfoInt.h index a76153602..93e674504 100644 --- a/open-vm-tools/lib/misc/hostinfoInt.h +++ b/open-vm-tools/lib/misc/hostinfoInt.h @@ -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 /* diff --git a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c index 0baa48eae..cf52b7f36 100644 --- a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c +++ b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c @@ -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, diff --git a/open-vm-tools/services/plugins/vix/vixTools.c b/open-vm-tools/services/plugins/vix/vixTools.c index ccf792808..0ab9b4393 100644 --- a/open-vm-tools/services/plugins/vix/vixTools.c +++ b/open-vm-tools/services/plugins/vix/vixTools.c @@ -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