Changeset 10814 in vbox
- Timestamp:
- Jul 22, 2008 1:50:54 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33593
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/VBoxGuest.h
r10797 r10814 1533 1533 VBGLR3DECL(int) VbglR3GuestPropConnect(uint32_t *pu32ClientId); 1534 1534 VBGLR3DECL(int) VbglR3GuestPropDisconnect(uint32_t u32ClientId); 1535 VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, c har *pszName, char *pszValue,char *pszFlags);1536 VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, c har *pszName,char *pszValue);1535 VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, const char *pszName, const char *pszValue, const char *pszFlags); 1536 VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, const char *pszName, const char *pszValue); 1537 1537 VBGLR3DECL(int) VbglR3GuestPropRead(uint32_t u32ClientId, const char *pszName, void *pvBuf, uint32_t cbBuf, char **ppszValue, uint64_t *pu64Timestamp, char **ppszFlags, uint32_t *pcbBufActual); 1538 1538 VBGLR3DECL(int) VbglR3GuestPropReadValue(uint32_t ClientId, const char *pszName, char *pszValue, uint32_t cchValue, uint32_t *pcchValueActual); -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp
r10797 r10814 91 91 * @param pszFlags The flags for the property 92 92 */ 93 VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, c har *pszName, char *pszValue,char *pszFlags)93 VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, const char *pszName, const char *pszValue, const char *pszFlags) 94 94 { 95 95 int rc; … … 103 103 Msg.hdr.u32Function = SET_PROP_VALUE; 104 104 Msg.hdr.cParms = 2; 105 VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);106 VbglHGCMParmPtrSet(&Msg.value, pszValue, strlen(pszValue) + 1);107 VbglHGCMParmPtrSet(&Msg.flags, pszFlags, strlen(pszFlags) + 1);105 VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 106 VbglHGCMParmPtrSet(&Msg.value, const_cast<char *>(pszValue), strlen(pszValue) + 1); 107 VbglHGCMParmPtrSet(&Msg.flags, const_cast<char *>(pszFlags), strlen(pszFlags) + 1); 108 108 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 109 109 if (RT_SUCCESS(rc)) … … 118 118 Msg.hdr.u32Function = DEL_PROP; 119 119 Msg.hdr.cParms = 1; 120 VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);120 VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 121 121 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 122 122 if (RT_SUCCESS(rc)) … … 138 138 * property's flags field will be left unchanged 139 139 */ 140 VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, c har *pszName,char *pszValue)140 VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, const char *pszName, const char *pszValue) 141 141 { 142 142 int rc; … … 150 150 Msg.hdr.u32Function = SET_PROP_VALUE; 151 151 Msg.hdr.cParms = 2; 152 VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);153 VbglHGCMParmPtrSet(&Msg.value, pszValue, strlen(pszValue) + 1);152 VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 153 VbglHGCMParmPtrSet(&Msg.value, const_cast<char *>(pszValue), strlen(pszValue) + 1); 154 154 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 155 155 if (RT_SUCCESS(rc)) … … 164 164 Msg.hdr.u32Function = DEL_PROP; 165 165 Msg.hdr.cParms = 1; 166 VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);166 VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 167 167 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 168 168 if (RT_SUCCESS(rc)) … … 228 228 if (RT_SUCCESS(rc) && (ppszFlags != NULL)) 229 229 { 230 bool found = false; 231 size_t i = 0; 232 char *pcBuf = reinterpret_cast<char *>(pvBuf); 233 for (; i < cbBuf && !found; ++i) 234 if (0 == pcBuf[i]) 235 found = true; 236 if (!found) 237 /* To my mind this is an internal error, but whatever */ 230 char *pszEos = reinterpret_cast<char *>(memchr(pvBuf, '\0', cbBuf)); 231 if (pszEos) 232 *ppszFlags = pszEos + 1; 233 else 238 234 rc = VERR_TOO_MUCH_DATA; 239 else240 *ppszFlags = pcBuf + i;241 235 } 242 236 return rc; … … 248 242 * 249 243 * @returns VBox status code. 250 * @retval VINF_SUCCESS on success, pszValue containing valid data. 251 * @retval VERR_NOT_FOUND if the key wasn't found. 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. 246 * @retval VERR_TOO_MUCH_DATA if we were unable to determine the right size 247 * to allocate for the buffer. This can happen as the result of a 248 * race between our allocating space and the host changing the 249 * property value. 252 250 * 253 251 * @param u32ClientId The client id returned by VbglR3ClipboardConnect(). … … 263 261 void *pvBuf = RTMemAlloc(cchBuf); 264 262 char *pszValue = NULL; 263 *ppszValue = NULL; 265 264 if (NULL == pvBuf) 266 265 rc = VERR_NO_MEMORY; 267 266 if (RT_SUCCESS(rc)) 268 267 { 269 rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 270 &pszValue, NULL, NULL, &cchBuf); 268 /* There is a race here between our reading the property size and the 269 * host changing the value before we read it. Try up to ten times and 270 * report the problem if that fails. */ 271 bool finish = false; 272 for (unsigned i = 0; (i < 10) && !finish; ++i) 273 { 274 rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 275 &pszValue, NULL, NULL, &cchBuf); 276 if (VERR_BUFFER_OVERFLOW == rc) 277 { 278 pvBuf = RTMemRealloc(pvBuf, cchBuf); 279 if (NULL == pvBuf) 280 rc = VERR_NO_MEMORY; 281 } 282 if (rc != VERR_BUFFER_OVERFLOW) 283 finish = true; 284 } 271 285 if (VERR_BUFFER_OVERFLOW == rc) 272 { 273 /** @todo how should we handle the race condition here? */ 274 pvBuf = RTMemRealloc(pvBuf, cchBuf); 275 if (pvBuf != NULL) 276 rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 277 &pszValue, NULL, NULL, NULL); 278 else 279 rc = VERR_NO_MEMORY; 280 if (VERR_BUFFER_OVERFLOW == rc) 281 /* VERR_BUFFER_OVERFLOW has a different meaning here as a 282 * return code */ 283 rc = VERR_TOO_MUCH_DATA; 284 } 286 /* VERR_BUFFER_OVERFLOW has a different meaning here as a 287 * return code, but we need to report the race. */ 288 rc = VERR_TOO_MUCH_DATA; 285 289 } 286 290 if (RT_SUCCESS(rc)) -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibVideo.cpp
r10797 r10814 246 246 using namespace guestProp; 247 247 248 char szModeName[MAX_NAME_LEN ];249 char szModeParms[MAX_VALUE_LEN ];248 char szModeName[MAX_NAME_LEN + 1]; 249 char szModeParms[MAX_VALUE_LEN + 1]; 250 250 uint32_t u32ClientId = 0; 251 251 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName); … … 290 290 if (RT_SUCCESS(rc)) 291 291 { 292 char szModeName[MAX_NAME_LEN ];292 char szModeName[MAX_NAME_LEN + 1]; 293 293 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName); 294 294 /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */ -
trunk/src/VBox/HostServices/GuestProperties/service.cpp
r10797 r10814 196 196 /* Validate the format of the key. */ 197 197 /* Only accept names in valid Utf8. */ 198 rc = RTStrValidateEncodingEx(pszKey, cbKey , 0);198 rc = RTStrValidateEncodingEx(pszKey, cbKey - 1, 0); 199 199 if (RT_SUCCESS(rc)) 200 200 /* We want the byte length, not the Utf8 length */ … … 226 226 /* Validate the format of the value. */ 227 227 /* Only accept values in valid Utf8 */ 228 rc = RTStrValidateEncodingEx(pszValue, cbValue , 0);228 rc = RTStrValidateEncodingEx(pszValue, cbValue - 1, 0); 229 229 if (RT_SUCCESS(rc)) 230 230 /* We want the byte length, not the Utf8 length */ -
trunk/src/VBox/Main/ConsoleImpl.cpp
r10797 r10814 3561 3561 VBOXHGCMSVCPARM parm[3]; 3562 3562 Utf8Str Utf8Key = aKey; 3563 Utf8Str Utf8Value (MAX_VALUE_LEN );3563 Utf8Str Utf8Value (MAX_VALUE_LEN + 1); 3564 3564 3565 3565 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; … … 3570 3570 parm[1].type = VBOX_HGCM_SVC_PARM_PTR; 3571 3571 parm[1].u.pointer.addr = Utf8Value.mutableRaw(); 3572 parm[1].u.pointer.size = MAX_VALUE_LEN ;3572 parm[1].u.pointer.size = MAX_VALUE_LEN + 1; 3573 3573 int vrc = mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", GET_CONFIG_KEY_HOST, 3574 3574 3, &parm[0]); … … 4180 4180 { 4181 4181 using namespace guestProp; 4182 char szKeyName[MAX_NAME_LEN ];4183 char szKeyValue[MAX_VALUE_LEN ];4184 char szExtraDataName[VBOX_SHARED_INFO_PREFIX_LEN + MAX_NAME_LEN ];4185 vrc = CFGMR3GetValueName (pValue, szKeyName, MAX_NAME_LEN);4182 char szKeyName[MAX_NAME_LEN + 1]; 4183 char szKeyValue[MAX_VALUE_LEN + 1]; 4184 char szExtraDataName[VBOX_SHARED_INFO_PREFIX_LEN + MAX_NAME_LEN + 1]; 4185 vrc = CFGMR3GetValueName (pValue, szKeyName, sizeof(szKeyName)); 4186 4186 if (RT_SUCCESS(vrc)) 4187 4187 vrc = CFGMR3QueryString (pRegistry, szKeyName, szKeyValue, sizeof(szKeyValue)); … … 4224 4224 4225 4225 /* Now see if a lookup of the name in the CFGM node succeeds. */ 4226 char szKeyValue[MAX_VALUE_LEN ];4226 char szKeyValue[MAX_VALUE_LEN + 1]; 4227 4227 vrc = CFGMR3QueryString (pRegistry, pszCFGMValueName, szKeyValue, sizeof(szKeyValue)); 4228 4228 /* And delete it from the extra data if it failed. */
Note:
See TracChangeset
for help on using the changeset viewer.