- Timestamp:
- Jul 15, 2009 9:22:54 PM (15 years ago)
- Location:
- trunk/src/VBox/HostServices/GuestProperties
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/GuestProperties/service.cpp
r21507 r21629 360 360 361 361 /** 362 * Checking that the name passed by the guest fits our criteria for a 363 * property name. 362 * Check that a string fits our criteria for a property name. 364 363 * 365 364 * @returns IPRT status code 366 * @param pszName the name passed by the guest367 * @param cbName the number of bytes pszName points to, including the365 * @param pszName the string to check, must be valid Utf8 366 * @param cbName the number of bytes @a pszName points to, including the 368 367 * terminating '\0' 369 368 * @thread HGCM … … 372 371 { 373 372 LogFlowFunc(("cbName=%d\n", cbName)); 374 375 /*376 * Validate the name, checking that it's proper UTF-8 and has377 * a string terminator.378 */379 373 int rc = VINF_SUCCESS; 380 374 if (RT_SUCCESS(rc) && (cbName < 2)) 381 375 rc = VERR_INVALID_PARAMETER; 382 if (RT_SUCCESS(rc))383 rc = RTStrValidateEncodingEx(pszName, RT_MIN(cbName, (uint32_t) MAX_NAME_LEN),384 RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);385 376 for (unsigned i = 0; RT_SUCCESS(rc) && i < cbName; ++i) 386 377 if (pszName[i] == '*' || pszName[i] == '?' || pszName[i] == '|') … … 392 383 393 384 /** 394 * Check that the data passed by the guest fits our criteria for the value of 395 * a guest property. 385 * Check a string fits our criteria for the value of a guest property. 396 386 * 397 387 * @returns IPRT status code 398 * @param pszValue the value to store in the property 399 * @param cbValue the number of bytes in the buffer pszValue points to 388 * @param pszValue the string to check, must be valid Utf8 389 * @param cbValue the length in bytes of @a pszValue, including the 390 * terminator 400 391 * @thread HGCM 401 392 */ … … 404 395 LogFlowFunc(("cbValue=%d\n", cbValue)); 405 396 406 /*407 * Validate the value, checking that it's proper UTF-8 and has408 * a string terminator.409 */410 397 int rc = VINF_SUCCESS; 411 398 if (RT_SUCCESS(rc) && cbValue == 0) 412 399 rc = VERR_INVALID_PARAMETER; 413 if (RT_SUCCESS(rc))414 rc = RTStrValidateEncodingEx(pszValue, RT_MIN(cbValue, (uint32_t) MAX_VALUE_LEN),415 RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);416 400 if (RT_SUCCESS(rc)) 417 401 LogFlow((" pszValue=%s\n", cbValue > 0 ? pszValue : NULL)); … … 535 519 LogFlowThisFunc(("\n")); 536 520 if ( cParms != 4 /* Hardcoded value as the next lines depend on it. */ 537 || RT_FAILURE (paParms[0].get Pointer ((const void **) &pcszName, &cchName))/* name */538 || RT_FAILURE (paParms[1].get Pointer ((void **) &pchBuf, &cchBuf))/* buffer */521 || RT_FAILURE (paParms[0].getString(&pcszName, &cchName)) /* name */ 522 || RT_FAILURE (paParms[1].getBuffer((void **) &pchBuf, &cchBuf)) /* buffer */ 539 523 ) 540 524 rc = VERR_INVALID_PARAMETER; … … 619 603 if ( RT_SUCCESS(rc) 620 604 && ( (cParms < 2) || (cParms > 3) /* Hardcoded value as the next lines depend on it. */ 621 || RT_FAILURE(paParms[0].getPointer ((const void **) &pcszName, 622 &cchName)) /* name */ 623 || RT_FAILURE(paParms[1].getPointer ((const void **) &pcszValue, 624 &cchValue)) /* value */ 605 || RT_FAILURE(paParms[0].getString(&pcszName, &cchName)) /* name */ 606 || RT_FAILURE(paParms[1].getString(&pcszValue, &cchValue)) /* value */ 625 607 || ( (3 == cParms) 626 && RT_FAILURE(paParms[2].getPointer ((const void **) &pcszFlags, 627 &cchFlags)) /* flags */ 608 && RT_FAILURE(paParms[2].getString(&pcszFlags, &cchFlags)) /* flags */ 628 609 ) 629 610 ) … … 715 696 */ 716 697 if ( (cParms != 1) /* Hardcoded value as the next lines depend on it. */ 717 || RT_FAILURE(paParms[0].getPointer ((const void **) &pcszName, 718 &cbName)) /* name */ 698 || RT_FAILURE(paParms[0].getString(&pcszName, &cbName)) /* name */ 719 699 ) 720 700 rc = VERR_INVALID_PARAMETER; … … 777 757 LogFlowThisFunc(("\n")); 778 758 if ( (cParms != 3) /* Hardcoded value as the next lines depend on it. */ 779 || RT_FAILURE(paParms[0].getPointer ((const void **) &pcchPatterns, 780 &cchPatterns)) /* patterns */ 781 || RT_FAILURE(paParms[1].getPointer ((void **) &pchBuf, &cchBuf)) /* return buffer */ 759 || RT_FAILURE(paParms[0].getString(&pcchPatterns, &cchPatterns)) /* patterns */ 760 || RT_FAILURE(paParms[1].getBuffer((void **) &pchBuf, &cchBuf)) /* return buffer */ 782 761 ) 783 762 rc = VERR_INVALID_PARAMETER; … … 789 768 */ 790 769 char pszPatterns[MAX_PATTERN_LEN]; 791 if (NULL == pcchPatterns) 792 pszPatterns[0] = '\0'; 793 else 794 { 795 for (unsigned i = 0; i < cchPatterns - 1; ++i) 796 if (pcchPatterns[i] != '\0') 797 pszPatterns[i] = pcchPatterns[i]; 798 else 799 pszPatterns[i] = '|'; 800 pszPatterns[cchPatterns - 1] = '\0'; 801 } 770 for (unsigned i = 0; i < cchPatterns - 1; ++i) 771 if (pcchPatterns[i] != '\0') 772 pszPatterns[i] = pcchPatterns[i]; 773 else 774 pszPatterns[i] = '|'; 775 pszPatterns[cchPatterns - 1] = '\0'; 802 776 803 777 /* … … 885 859 char *pchBuf; 886 860 uint32_t cchBuf; 887 rc = paParms[2].get Pointer((void **) &pchBuf, &cchBuf);861 rc = paParms[2].getBuffer((void **) &pchBuf, &cchBuf); 888 862 if (RT_SUCCESS(rc)) 889 863 { … … 936 910 LogFlowThisFunc(("\n")); 937 911 if ( (cParms != 4) /* Hardcoded value as the next lines depend on it. */ 938 || RT_FAILURE(paParms[0].getPointer ((void **) &pszPatterns, &cchPatterns)) /* patterns */ 939 || pszPatterns[cchPatterns - 1] != '\0' /* The patterns string must be zero-terminated */ 940 /** @todo r=bird: What if cchPatterns is 0? pszPatterns is NULL then, and if it wasn't, you'd access memory 941 * before what it points to. Add a getString() method? Please, check *all* similar cases. 942 * Remember that the guest is not trusted. :-) */ 943 || RT_FAILURE(paParms[1].getUInt64 (&u64Timestamp)) /* timestamp */ 944 || RT_FAILURE(paParms[2].getPointer ((void **) &pchBuf, &cchBuf)) /* return buffer */ 945 || cchBuf < 1 912 || RT_FAILURE(paParms[0].getString(&pszPatterns, &cchPatterns)) /* patterns */ 913 || RT_FAILURE(paParms[1].getUInt64(&u64Timestamp)) /* timestamp */ 914 || RT_FAILURE(paParms[2].getBuffer((void **) &pchBuf, &cchBuf)) /* return buffer */ 946 915 ) 947 916 rc = VERR_INVALID_PARAMETER; … … 1028 997 const char *pszPatterns; 1029 998 uint32_t cchPatterns; 1030 it->mParms[0].get Pointer((void **)&pszPatterns, &cchPatterns);999 it->mParms[0].getString(&pszPatterns, &cchPatterns); 1031 1000 if (prop.Matches(pszPatterns)) 1032 1001 { -
trunk/src/VBox/HostServices/GuestProperties/testcase/Makefile.kmk
r18422 r21629 23 23 include $(KBUILD_PATH)/subheader.kmk 24 24 25 ifdef VBOX_WITH_TESTCASES 26 # 27 # Case conversion testcase. 28 # 29 PROGRAMS += tstGuestPropSvc 30 tstGuestPropSvc_TEMPLATE = VBOXR3TSTEXE 31 # The second define here is to ensure that the testcase will run fast, without 32 # waiting for any thread synchronisation. 33 tstGuestPropSvc_DEFS = VBOX_WITH_HGCM VBOX_GUEST_PROP_TEST_NOTHREAD 34 tstGuestPropSvc_SOURCES = tstGuestPropSvc.cpp ../service.cpp 35 tstGuestPropSvc_LIBS = $(LIB_RUNTIME) 25 if defined(VBOX_WITH_TESTCASES) && !defined(VBOX_ONLY_ADDITIONS) && !defined(VBOX_ONLY_SDK) 36 26 37 # Set this in LocalConfig.kmk if you are working on the guest property service 38 # to automatically run the testcase at build time. 39 ifdef VBOX_RUN_GUEST_PROPERTY_TEST 40 ifndef VBOX_ONLY_SDK 41 TESTING += $(PATH_tstGuestPropSvc)/tstGuestPropSvc.run 42 OTHERS += $(PATH_tstGuestPropSvc)/tstGuestPropSvc.run 27 # Set this in LocalConfig.kmk if you are working on the guest property 28 # service to automatically run the testcase at build time. 29 # OTHERS += $(PATH_tstGuestPropSvc)/tstGuestPropSvc.run 30 # 31 32 PROGRAMS += tstGuestPropSvc 33 TESTING += $(PATH_tstGuestPropSvc)/tstGuestPropSvc.run 34 tstGuestPropSvc_TEMPLATE = VBOXR3TSTEXE 35 # The second define here is to ensure that the testcase will run fast, 36 # without waiting for any thread synchronisation. 37 tstGuestPropSvc_DEFS = VBOX_WITH_HGCM VBOX_GUEST_PROP_TEST_NOTHREAD 38 tstGuestPropSvc_SOURCES = tstGuestPropSvc.cpp ../service.cpp 39 tstGuestPropSvc_LIBS = $(LIB_RUNTIME) 40 43 41 $$(PATH_tstGuestPropSvc)/tstGuestPropSvc.run: $$(INSTARGET_tstGuestPropSvc) 44 42 export VBOX_LOG_DEST=nofile; $(INSTARGET_tstGuestPropSvc) quiet 45 43 $(QUIET)$(APPEND) -t "$@" "done" 46 endif 44 47 45 endif 48 49 endif # VBOX_WITH_TESTCASES50 51 46 52 47 include $(KBUILD_PATH)/subfooter.kmk
Note:
See TracChangeset
for help on using the changeset viewer.