Changeset 10860 in vbox for trunk/src/VBox/Additions/common/VBoxGuestLib
- Timestamp:
- Jul 24, 2008 4:56:08 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33676
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp
r10834 r10860 243 243 * @returns VBox status code. 244 244 * @retval VINF_SUCCESS on success, *ppszValue containing valid data. 245 * @retval VERR_NOT_FOUND if the key wasn't found and *ppszValue set to NULL.245 * @retval VERR_NOT_FOUND if the key wasn't found. 246 246 * @retval VERR_TOO_MUCH_DATA if we were unable to determine the right size 247 247 * to allocate for the buffer. This can happen as the result of a … … 250 250 * 251 251 * @param u32ClientId The client id returned by VbglR3ClipboardConnect(). 252 * @param pszName The value to read. Utf8252 * @param pszName The value to read. Must be valid UTF-8. 253 253 * @param ppszValue Where to store the pointer to the value returned. 254 * This is always set to NULL or to the result, even 255 * on failure. 254 256 */ 255 257 VBGLR3DECL(int) VbglR3GuestPropReadValueAlloc(uint32_t u32ClientId, … … 257 259 char **ppszValue) 258 260 { 259 int rc = VINF_SUCCESS; 260 char *pszValue = NULL; 261 /* 262 * Quick input validation. 263 */ 264 AssertPtr(ppszValue); 261 265 *ppszValue = NULL; 262 263 /* There is a race here between our reading the property size and the 266 AssertPtrReturn(pszName, VERR_INVALID_PARAMETER); 267 268 /* 269 * There is a race here between our reading the property size and the 264 270 * host changing the value before we read it. Try up to ten times and 265 * report the problem if that fails. */ 266 bool finish = false; 267 /* We leave a bit of space here in case the maximum value is raised. */ 268 uint32_t cchBuf = MAX_VALUE_LEN + 1024; 269 void *pvBuf = NULL; 270 for (unsigned i = 0; (i < 10) && !finish; ++i) 271 { 271 * report the problem if that fails. 272 */ 273 char *pszValue = NULL; 274 void *pvBuf = NULL; 275 uint32_t cchBuf = MAX_VALUE_LEN; 276 int rc = VERR_BUFFER_OVERFLOW; 277 for (unsigned i = 0; i < 10 && rc == VERR_BUFFER_OVERFLOW; ++i) 278 { 279 /* We leave a bit of space here in case the maximum value is raised. */ 280 cchBuf += 1024; 272 281 void *pvTmpBuf = RTMemRealloc(pvBuf, cchBuf); 273 if (NULL == pvTmpBuf) 274 { 275 RTMemFree(pvBuf); 276 rc = VERR_NO_MEMORY; 277 } 278 else 282 if (pvTmpBuf) 279 283 { 280 284 pvBuf = pvTmpBuf; … … 282 286 &pszValue, NULL, NULL, &cchBuf); 283 287 } 284 if (VERR_BUFFER_OVERFLOW == rc)285 /* Leave a bit of extra space to be safe */286 cchBuf += 1024;287 288 else 288 finish = true; 289 } 290 if (VERR_BUFFER_OVERFLOW == rc) 291 /* VERR_BUFFER_OVERFLOW has a different meaning here as a 292 * return code, but we need to report the race. */ 293 rc = VERR_TOO_MUCH_DATA; 294 if (RT_SUCCESS(rc)) 289 rc = VERR_NO_MEMORY; 290 } 291 if (RT_SUCCESS(rc)) 292 { 293 Assert(pszValue == (char *)pvBuf); 295 294 *ppszValue = pszValue; 295 } 296 else 297 { 298 RTMemFree(pvBuf); 299 if (rc == VERR_BUFFER_OVERFLOW) 300 /* VERR_BUFFER_OVERFLOW has a different meaning here as a 301 * return code, but we need to report the race. */ 302 rc = VERR_TOO_MUCH_DATA; 303 } 304 296 305 return rc; 297 306 } … … 300 309 * Free the memory used by VbglR3GuestPropReadValueAlloc for returning a 301 310 * value. 302 * 311 * 303 312 * @param pszValue the memory to be freed. NULL pointers will be ignored. 304 313 */
Note:
See TracChangeset
for help on using the changeset viewer.