Changeset 37256 in vbox
- Timestamp:
- May 30, 2011 12:39:03 PM (14 years ago)
- Location:
- trunk/src/VBox/Additions/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibAdditions.cpp
r37141 r37256 179 179 180 180 181 int vbglR3QueryRegistryString(HKEY hKey, const char *pszValName, char *pszBuffer, size_t cchBuffer) 182 { 183 AssertReturn(pszValName, VERR_INVALID_PARAMETER); 184 AssertReturn(pszBuffer, VERR_INVALID_POINTER); 185 AssertReturn(cchBuffer, VERR_INVALID_PARAMETER); 186 187 int rc = VINF_SUCCESS; 188 189 DWORD dwType; 190 DWORD dwSize = (DWORD)cchBuffer; 191 LONG lRet = RegQueryValueEx(hKey, pszValName, NULL, &dwType, (BYTE*)(LPCTSTR)pszBuffer, &dwSize); 192 if (lRet == ERROR_SUCCESS) 193 { 194 rc = dwType == REG_SZ 195 ? VINF_SUCCESS : VERR_INVALID_PARAMETER; 196 } 197 else 198 rc = RTErrConvertFromWin32(lRet); 199 return rc; 200 } 201 202 181 203 /** 182 204 * Retrieves the installed Guest Additions version and/or revision. … … 186 208 * (major.minor.build). NULL is accepted. The returned 187 209 * pointer must be freed using RTStrFree().* 188 * @param ppszVerEx 210 * @param ppszVerExt Receives pointer of allocated full version string 189 211 * (raw version + vendor suffix(es)). NULL is 190 212 * accepted. The returned pointer must be freed using … … 194 216 * RTStrFree(). 195 217 */ 196 VBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszVerEx , char **ppszRev)218 VBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszVerExt, char **ppszRev) 197 219 { 198 220 /* … … 201 223 if (ppszVer) 202 224 *ppszVer = NULL; 203 if (ppszVerEx )204 *ppszVerEx = NULL;225 if (ppszVerExt) 226 *ppszVerExt = NULL; 205 227 if (ppszRev) 206 228 *ppszRev = NULL; … … 215 237 * Version. 216 238 */ 217 /** @todo r=bird: This code has broken error handling: 1. Errors are 218 * overwritten and hidden, leaving return values undefined. 219 * 2. On error, memory could be leaked. 220 * Also, just use a static 32-byte buffer instead of allocating 221 * three! In fact, why not just factor out the string value query? */ 222 LONG l; 223 DWORD dwType; 224 DWORD dwSize = 32; 225 char *pszTmp; 239 char szTemp[32]; 226 240 if (ppszVer) 227 241 { 228 pszTmp = (char*)RTMemAlloc(dwSize); 229 if (pszTmp) 230 { 231 l = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize); 232 if (l == ERROR_SUCCESS) 233 { 234 if (dwType == REG_SZ) 235 rc = RTStrDupEx(ppszVer, pszTmp); 236 else 237 rc = VERR_INVALID_PARAMETER; 238 } 239 else 240 { 241 rc = RTErrConvertFromWin32(l); 242 } 243 RTMemFree(pszTmp); 244 } 245 else 246 rc = VERR_NO_MEMORY; 247 } 248 if (ppszVerEx) 249 { 250 dwSize = 32; /* Reset */ 251 pszTmp = (char*)RTMemAlloc(dwSize); 252 if (pszTmp) 253 { 254 l = RegQueryValueEx(hKey, "VersionEx", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize); 255 if (l == ERROR_SUCCESS) 256 { 257 if (dwType == REG_SZ) 258 rc = RTStrDupEx(ppszVerEx, pszTmp); 259 else 260 rc = VERR_INVALID_PARAMETER; 261 } 262 else 263 { 264 rc = RTErrConvertFromWin32(l); 265 } 266 RTMemFree(pszTmp); 267 } 268 else 269 rc = VERR_NO_MEMORY; 242 rc = vbglR3QueryRegistryString(hKey, "Version", szTemp, sizeof(szTemp)); 243 if (RT_SUCCESS(rc)) 244 rc = RTStrDupEx(ppszVer, szTemp); 245 } 246 247 if ( RT_SUCCESS(rc) 248 && ppszVerExt) 249 { 250 rc = vbglR3QueryRegistryString(hKey, "VersionExt", szTemp, sizeof(szTemp)); 251 if (RT_SUCCESS(rc)) 252 rc = RTStrDupEx(ppszVerExt, szTemp); 270 253 } 271 254 … … 273 256 * Revision. 274 257 */ 275 if (ppszRev) 276 { 277 dwSize = 32; /* Reset */ 278 pszTmp = (char*)RTMemAlloc(dwSize); 279 if (pszTmp) 280 { 281 l = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize); 282 if (l == ERROR_SUCCESS) 283 { 284 if (dwType == REG_SZ) 285 rc = RTStrDupEx(ppszRev, pszTmp); 286 else 287 rc = VERR_INVALID_PARAMETER; 288 } 289 else 290 { 291 rc = RTErrConvertFromWin32(l); 292 } 293 RTMemFree(pszTmp); 294 } 295 else 296 rc = VERR_NO_MEMORY; 297 298 if (RT_FAILURE(rc) && ppszVer) 299 { 258 if ( RT_SUCCESS(rc) 259 && ppszRev) 260 { 261 rc = vbglR3QueryRegistryString(hKey, "Revision", szTemp, sizeof(szTemp)); 262 if (RT_SUCCESS(rc)) 263 rc = RTStrDupEx(ppszRev, szTemp); 264 } 265 266 int rc2 = vbglR3CloseAdditionsWinStoragePath(hKey); 267 if (RT_SUCCESS(rc)) 268 rc = rc2; 269 else 270 { 271 /* Clean up allocated strings on error. */ 272 if (*ppszVer) 300 273 RTStrFree(*ppszVer); 301 *ppszVer = NULL; 302 } 303 } 304 rc = vbglR3CloseAdditionsWinStoragePath(hKey); 274 if (*ppszVerExt) 275 RTStrFree(*ppszVerExt); 276 if (*ppszRev) 277 RTStrFree(*ppszRev); 278 } 305 279 } 306 280 else … … 310 284 * into this binary. 311 285 */ 312 rc = vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerEx , ppszRev);286 rc = vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerExt, ppszRev); 313 287 } 314 288 return rc; … … 318 292 * On non-Windows platforms just return the compile-time version string. 319 293 */ 320 return vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerEx , ppszRev);294 return vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerExt, ppszRev); 321 295 #endif /* !RT_OS_WINDOWS */ 322 296 } -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r37019 r37256 190 190 */ 191 191 char *pszAddVer; 192 char *pszAddVerEx ;192 char *pszAddVerExt; 193 193 char *pszAddRev; 194 rc = VbglR3GetAdditionsVersion(&pszAddVer, &pszAddVerEx , &pszAddRev);194 rc = VbglR3GetAdditionsVersion(&pszAddVer, &pszAddVerExt, &pszAddRev); 195 195 VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Version", 196 196 "%s", RT_FAILURE(rc) ? "" : pszAddVer); 197 VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/VersionEx ",198 "%s", RT_FAILURE(rc) ? "" : pszAddVerEx );197 VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/VersionExt", 198 "%s", RT_FAILURE(rc) ? "" : pszAddVerExt); 199 199 VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Revision", 200 200 "%s", RT_FAILURE(rc) ? "" : pszAddRev); … … 202 202 { 203 203 RTStrFree(pszAddVer); 204 RTStrFree(pszAddVerEx );204 RTStrFree(pszAddVerExt); 205 205 RTStrFree(pszAddRev); 206 206 }
Note:
See TracChangeset
for help on using the changeset viewer.