Changeset 93891 in vbox
- Timestamp:
- Feb 22, 2022 6:08:39 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/HostServices/GuestPropertySvc.h
r93115 r93891 66 66 #define GUEST_PROP_F_ALLFLAGS (GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_READONLY | GUEST_PROP_F_TRANSRESET) 67 67 /** @} */ 68 69 /** 70 * Check that a string fits our criteria for a property name. 71 * 72 * @returns IPRT status code 73 * @param pszName the string to check, must be valid Utf8 74 * @param cbName the number of bytes @a pszName points to, including the terminating character. 75 */ 76 DECLINLINE(int) GuestPropValidateName(const char *pszName, uint32_t cbName) 77 { 78 /* Property name is expected to be at least 1 charecter long plus terminating character. */ 79 AssertReturn(cbName >= 2, VERR_INVALID_PARAMETER); 80 AssertReturn(cbName < GUEST_PROP_MAX_NAME_LEN, VERR_INVALID_PARAMETER); 81 82 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 83 84 AssertReturn(memchr(pszName, '*', cbName) == NULL, VERR_INVALID_PARAMETER); 85 AssertReturn(memchr(pszName, '?', cbName) == NULL, VERR_INVALID_PARAMETER); 86 AssertReturn(memchr(pszName, '|', cbName) == NULL, VERR_INVALID_PARAMETER); 87 88 return VINF_SUCCESS; 89 } 90 91 /** 92 * Check a string fits our criteria for the value of a guest property. 93 * 94 * @returns IPRT status code 95 * @param pszValue the string to check, must be valid Utf8 96 * @param cbValue the length in bytes of @a pszValue, including the 97 * terminator 98 * @thread HGCM 99 */ 100 DECLINLINE(int) GuestPropValidateValue(const char *pszValue, uint32_t cbValue) 101 { 102 AssertPtrReturn(pszValue, VERR_INVALID_POINTER); 103 104 /* Zero-length values are possible, however buffer should contain terminating character at least. */ 105 AssertReturn(cbValue > 0, VERR_INVALID_PARAMETER); 106 AssertReturn(cbValue < GUEST_PROP_MAX_VALUE_LEN, VERR_INVALID_PARAMETER); 107 108 return VINF_SUCCESS; 109 } 68 110 69 111 /** -
trunk/src/VBox/HostServices/GuestProperties/VBoxGuestPropSvc.cpp
r93115 r93891 416 416 static DECLCALLBACK(int) reqThreadFn(RTTHREAD ThreadSelf, void *pvUser); 417 417 uint64_t getCurrentTimestamp(void); 418 int validateName(const char *pszName, uint32_t cbName);419 int validateValue(const char *pszValue, uint32_t cbValue);420 418 int setPropertyBlock(uint32_t cParms, VBOXHGCMSVCPARM paParms[]); 421 419 int getProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[]); … … 471 469 this->mPrevTimestamp = u64NanoTS; 472 470 return u64NanoTS; 473 }474 475 /**476 * Check that a string fits our criteria for a property name.477 *478 * @returns IPRT status code479 * @param pszName the string to check, must be valid Utf8480 * @param cbName the number of bytes @a pszName points to, including the481 * terminating '\0'482 * @thread HGCM483 */484 int Service::validateName(const char *pszName, uint32_t cbName)485 {486 LogFlowFunc(("cbName=%d\n", cbName));487 int rc = VINF_SUCCESS;488 if (RT_SUCCESS(rc) && (cbName < 2))489 rc = VERR_INVALID_PARAMETER;490 for (unsigned i = 0; RT_SUCCESS(rc) && i < cbName; ++i)491 if (pszName[i] == '*' || pszName[i] == '?' || pszName[i] == '|')492 rc = VERR_INVALID_PARAMETER;493 LogFlowFunc(("returning %Rrc\n", rc));494 return rc;495 }496 497 498 /**499 * Check a string fits our criteria for the value of a guest property.500 *501 * @returns IPRT status code502 * @param pszValue the string to check, must be valid Utf8503 * @param cbValue the length in bytes of @a pszValue, including the504 * terminator505 * @thread HGCM506 */507 int Service::validateValue(const char *pszValue, uint32_t cbValue)508 {509 LogFlowFunc(("cbValue=%d\n", cbValue)); RT_NOREF1(pszValue);510 511 int rc = VINF_SUCCESS;512 if (RT_SUCCESS(rc) && cbValue == 0)513 rc = VERR_INVALID_PARAMETER;514 if (RT_SUCCESS(rc))515 LogFlow((" pszValue=%s\n", cbValue > 0 ? pszValue : NULL));516 LogFlowFunc(("returning %Rrc\n", rc));517 return rc;518 471 } 519 472 … … 644 597 rc = VERR_INVALID_PARAMETER; 645 598 else 646 rc = validateName(pcszName, cbName);599 rc = GuestPropValidateName(pcszName, cbName); 647 600 if (RT_FAILURE(rc)) 648 601 { … … 736 689 */ 737 690 if (RT_SUCCESS(rc)) 738 rc = validateName(pcszName, cchName);691 rc = GuestPropValidateName(pcszName, cchName); 739 692 if (RT_SUCCESS(rc)) 740 rc = validateValue(pcszValue, cchValue);693 rc = GuestPropValidateValue(pcszValue, cchValue); 741 694 if ((3 == cParms) && RT_SUCCESS(rc)) 742 695 rc = RTStrValidateEncodingEx(pcszFlags, cchFlags, … … 869 822 && RT_SUCCESS(HGCMSvcGetCStr(&paParms[0], &pcszName, &cbName)) /* name */ 870 823 ) 871 rc = validateName(pcszName, cbName);824 rc = GuestPropValidateName(pcszName, cbName); 872 825 else 873 826 rc = VERR_INVALID_PARAMETER; … … 1342 1295 { 1343 1296 /* Send out a host notification */ 1344 rc = notifyHost(pszProperty, "", nsTimestamp, "");1297 rc = notifyHost(pszProperty, NULL, nsTimestamp, ""); 1345 1298 } 1346 1299 } … … 1388 1341 *pu8++ = 0; 1389 1342 1390 pHostCallbackData->pcszValue = (const char *)pu8; 1343 /* NULL value means property was deleted. */ 1344 pHostCallbackData->pcszValue = pszValue ? (const char *)pu8 : NULL; 1391 1345 memcpy(pu8, pszValue, cbValue); 1392 1346 pu8 += cbValue; -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r93835 r93891 5320 5320 </desc> 5321 5321 </param> 5322 <param name="fWasDeleted" type="boolean" dir="in"> 5323 <desc> 5324 The flag which indicates if property was deleted. 5325 </desc> 5326 </param> 5322 5327 </method> 5323 5328 -
trunk/src/VBox/Main/include/MachineImpl.h
r93548 r93891 1234 1234 const com::Utf8Str &aValue, 1235 1235 LONG64 aTimestamp, 1236 const com::Utf8Str &aFlags); 1236 const com::Utf8Str &aFlags, 1237 BOOL fWasDeleted); 1237 1238 HRESULT lockMedia(); 1238 1239 HRESULT unlockMedia(); … … 1390 1391 const com::Utf8Str &aValue, 1391 1392 LONG64 aTimestamp, 1392 const com::Utf8Str &aFlags); 1393 const com::Utf8Str &aFlags, 1394 BOOL fWasDeleted); 1393 1395 HRESULT lockMedia(); 1394 1396 HRESULT unlockMedia(); -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r93859 r93891 1849 1849 value.raw(), 1850 1850 pCBData->u64Timestamp, 1851 flags.raw()); 1851 flags.raw(), 1852 !pCBData->pcszValue); 1852 1853 if (SUCCEEDED(hrc)) 1853 1854 { -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r93639 r93891 5655 5655 ReturnComNotImplemented(); 5656 5656 #else // VBOX_WITH_GUEST_PROPS 5657 AssertReturn(RT_SUCCESS(GuestPropValidateName(aProperty.c_str(), (uint32_t)aProperty.length() + 1 /* '\0' */)), E_INVALIDARG); 5658 AssertReturn(RT_SUCCESS(GuestPropValidateValue(aValue.c_str(), (uint32_t)aValue.length() + 1 /* '\0' */)), E_INVALIDARG); 5659 5657 5660 HRESULT rc = i_setGuestPropertyToVM(aProperty, aValue, aFlags, /* fDelete = */ false); 5658 5661 if (rc == E_ACCESSDENIED) … … 5737 5740 GuestPropWriteFlags(it->second.mFlags, szFlags); 5738 5741 aFlags[i] = Utf8Str(szFlags); 5742 5743 AssertReturn(RT_SUCCESS(GuestPropValidateName(aNames[i].c_str(), (uint32_t)aNames[i].length() + 1 /* '\0' */)), E_INVALIDARG); 5744 AssertReturn(RT_SUCCESS(GuestPropValidateValue(aValues[i].c_str(), (uint32_t)aValues[i].length() + 1 /* '\0' */)), E_INVALIDARG); 5739 5745 } 5740 5746 … … 13572 13578 else 13573 13579 aFlags[i] = ""; 13580 13581 AssertReturn(RT_SUCCESS(GuestPropValidateName(aNames[i].c_str(), (uint32_t)aNames[i].length() + 1 /* '\0' */)), E_INVALIDARG); 13582 AssertReturn(RT_SUCCESS(GuestPropValidateValue(aValues[i].c_str(), (uint32_t)aValues[i].length() + 1 /* '\0' */)), E_INVALIDARG); 13574 13583 } 13575 13584 return S_OK; … … 13582 13591 const com::Utf8Str &aValue, 13583 13592 LONG64 aTimestamp, 13584 const com::Utf8Str &aFlags) 13593 const com::Utf8Str &aFlags, 13594 BOOL fWasDeleted) 13585 13595 { 13586 13596 LogFlowThisFunc(("\n")); … … 13611 13621 mHWData.backup(); 13612 13622 13613 bool fDelete = !aValue.length();13614 13623 HWData::GuestPropertyMap::iterator it = mHWData->mGuestProperties.find(aName); 13615 13624 if (it != mHWData->mGuestProperties.end()) 13616 13625 { 13617 if (!f Delete)13626 if (!fWasDeleted) 13618 13627 { 13619 13628 it->second.strValue = aValue; … … 13626 13635 mData->mGuestPropertiesModified = TRUE; 13627 13636 } 13628 else if (!f Delete)13637 else if (!fWasDeleted) 13629 13638 { 13630 13639 HWData::GuestProperty prop; … … 15046 15055 const com::Utf8Str &aValue, 15047 15056 LONG64 aTimestamp, 15048 const com::Utf8Str &aFlags) 15057 const com::Utf8Str &aFlags, 15058 BOOL fWasDeleted) 15049 15059 { 15050 15060 NOREF(aName); … … 15052 15062 NOREF(aTimestamp); 15053 15063 NOREF(aFlags); 15064 NOREF(fWasDeleted); 15054 15065 ReturnComNotImplemented(); 15055 15066 }
Note:
See TracChangeset
for help on using the changeset viewer.