<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>while debugging VBoxTray.exe crash bug, I found sometimes another crash occurs from following function:</DIV>
<DIV> </DIV><FONT size=2>
<DIV>VBGLR3DECL(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2>) VbglR3GetAdditionsVersion(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> **ppszVer, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> **ppszRev)</DIV></FONT>
<DIV> </DIV>
<DIV>There are two uses of SUCCEEDED/FAILED macros, which are wrong. When a registry key not present, it returns 2, which would be "succeeded"</DIV>
<DIV> </DIV><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV>#define</FONT></FONT><FONT size=2> SUCCEEDED(hr) ((HRESULT)(hr) >= 0)</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2></DIV></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV>#define</FONT></FONT><FONT size=2> FAILED(hr) ((HRESULT)(hr) < 0)</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>there might be some other locations, please check</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>code shown below, marked as RED are the incorrect use</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV><FONT size=2>
<DIV>VBGLR3DECL(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2>) VbglR3GetAdditionsVersion(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> **ppszVer, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> **ppszRev)</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> rc = VINF_SUCCESS;</DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV>#ifdef</FONT></FONT><FONT size=2> RT_OS_WINDOWS</DIV>
<DIV>HKEY hKey;</DIV>
<DIV>LONG r;</DIV>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Check the new path first. */</DIV></FONT></FONT><FONT size=2>
<DIV>r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"SOFTWARE\\Sun\\VirtualBox Guest Additions"</FONT></FONT><FONT size=2>, 0, KEY_READ, &hKey);</DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV># ifdef</FONT></FONT><FONT size=2> RT_ARCH_AMD64</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (r != ERROR_SUCCESS)</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Check Wow6432Node (for new entries). */</DIV></FONT></FONT><FONT size=2>
<DIV>r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions"</FONT></FONT><FONT size=2>, 0, KEY_READ, &hKey);</DIV>
<DIV>}</DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV># endif</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Still no luck? Then try the old xVM paths ... */</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (<FONT color=#ff0000>FAILED</FONT>(r))</DIV>
<DIV>{</DIV>
<DIV>r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"SOFTWARE\\Sun\\xVM VirtualBox Guest Additions"</FONT></FONT><FONT size=2>, 0, KEY_READ, &hKey);</DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV># ifdef</FONT></FONT><FONT size=2> RT_ARCH_AMD64</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (r != ERROR_SUCCESS)</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Check Wow6432Node (for new entries). */</DIV></FONT></FONT><FONT size=2>
<DIV>r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions"</FONT></FONT><FONT size=2>, 0, KEY_READ, &hKey);</DIV>
<DIV>}</DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV># endif</DIV></FONT></FONT><FONT size=2>
<DIV>}</DIV>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Did we get something worth looking at? */</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (<FONT color=#ff007f>SUCCEEDED</FONT>(r))</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Version. */</DIV></FONT></FONT><FONT size=2>
<DIV>DWORD dwType;</DIV>
<DIV>DWORD dwSize = 32;</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (ppszVer)</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> *pszVer = (</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2>*)RTMemAlloc(dwSize);</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (pszVer)</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (ERROR_SUCCESS == RegQueryValueEx(hKey, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"Version"</FONT></FONT><FONT size=2>, NULL, &dwType, (BYTE*)(LPCTSTR)pszVer, &dwSize))</DIV>
<DIV>*ppszVer = pszVer;</DIV>
<DIV>}</DIV>
<DIV>}</DIV>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Revision. */</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (ppszRev)</DIV>
<DIV>{</DIV>
<DIV>dwSize = 32; </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Reset */</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> *pszRev = (</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2>*)RTMemAlloc(dwSize);</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (pszRev)</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (ERROR_SUCCESS == RegQueryValueEx(hKey, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"Revision"</FONT></FONT><FONT size=2>, NULL, &dwType, (BYTE*)(LPCTSTR)pszRev, &dwSize))</DIV>
<DIV>*ppszRev = pszRev;</DIV>
<DIV>}</DIV>
<DIV>}</DIV>
<DIV>}</DIV>
<DIV>rc = RTErrConvertFromWin32(r);</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (NULL != hKey)</DIV>
<DIV>RegCloseKey(hKey);</DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV>#else</FONT></FONT><FONT size=2> </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* !RT_OS_WINDOWS */</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* On non-Windows platforms just return the compile-time version string atm. */</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Version. */</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (ppszVer)</DIV>
<DIV>rc = RTStrAPrintf(ppszVer, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"%s"</FONT></FONT><FONT size=2>, VBOX_VERSION_STRING);</DIV>
<DIV></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Revision. */</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (ppszRev)</DIV>
<DIV>rc = RTStrAPrintf(ppszRev, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"%s"</FONT></FONT><FONT size=2>, VBOX_SVN_REV);</DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV>#endif</FONT></FONT><FONT size=2> </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* !RT_OS_WINDOWS */</DIV></FONT></FONT><FONT size=2>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> rc;</DIV>
<DIV>}</DIV></FONT>
<DIV><FONT size=2> </DIV></FONT></td></tr></table>