[vbox-dev] incorrect use of SUCCEEDED/FAILED macros

Huihong Luo huisinro at yahoo.com
Tue Nov 3 22:37:11 GMT 2009


while debugging VBoxTray.exe crash bug, I found sometimes another crash occurs from following function:
 
VBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszRev)
 
There are two uses of SUCCEEDED/FAILED macros, which are wrong. When a registry key not present, it returns 2, which would be "succeeded"
 
#define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)
#define FAILED(hr) ((HRESULT)(hr) < 0)
 
there might be some other locations, please check
 
code shown below, marked as RED are the incorrect use
 
VBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszRev)
{
int rc = VINF_SUCCESS;
#ifdef RT_OS_WINDOWS
HKEY hKey;
LONG r;
/* Check the new path first. */
r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
# ifdef RT_ARCH_AMD64
if (r != ERROR_SUCCESS)
{
/* Check Wow6432Node (for new entries). */
r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
}
# endif
/* Still no luck? Then try the old xVM paths ... */
if (FAILED(r))
{
r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
# ifdef RT_ARCH_AMD64
if (r != ERROR_SUCCESS)
{
/* Check Wow6432Node (for new entries). */
r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
}
# endif
}
/* Did we get something worth looking at? */
if (SUCCEEDED(r))
{
/* Version. */
DWORD dwType;
DWORD dwSize = 32;
if (ppszVer)
{
char *pszVer = (char*)RTMemAlloc(dwSize);
if (pszVer)
{
if (ERROR_SUCCESS == RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)pszVer, &dwSize))
*ppszVer = pszVer;
}
}
/* Revision. */
if (ppszRev)
{
dwSize = 32; /* Reset */
char *pszRev = (char*)RTMemAlloc(dwSize);
if (pszRev)
{
if (ERROR_SUCCESS == RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)pszRev, &dwSize))
*ppszRev = pszRev;
}
}
}
rc = RTErrConvertFromWin32(r);
if (NULL != hKey)
RegCloseKey(hKey);
#else /* !RT_OS_WINDOWS */
/* On non-Windows platforms just return the compile-time version string atm. */
/* Version. */
if (ppszVer)
rc = RTStrAPrintf(ppszVer, "%s", VBOX_VERSION_STRING);
/* Revision. */
if (ppszRev)
rc = RTStrAPrintf(ppszRev, "%s", VBOX_SVN_REV);
#endif /* !RT_OS_WINDOWS */
return rc;
}
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20091103/25d8351f/attachment.html>


More information about the vbox-dev mailing list