Changeset 100521 in vbox
- Timestamp:
- Jul 11, 2023 4:47:42 PM (17 months ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/RemoteUSBDeviceImpl.h
r98103 r100521 51 51 52 52 // public initializer/uninitializer for internal purposes only 53 HRESULT init(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevDesc, bool fDescExt);53 HRESULT init(uint32_t u32ClientId, VRDEUSBDEVICEDESC const *pDevDesc, bool fDescExt); 54 54 void uninit(); 55 55 -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r100038 r100521 10765 10765 } 10766 10766 10767 /* Make sure that the string is null-terminated and its size is less than cchMax bytes. 10768 * Replace invalid UTF8 bytes with '?'. 10769 */ 10770 static int validateUtf8String(char *psz, size_t cchMax) 10771 { 10772 for (;;) 10773 { 10774 RTUNICP Cp; 10775 int vrc = RTStrGetCpNEx((const char **)&psz, &cchMax, &Cp); 10776 if (RT_SUCCESS(vrc)) 10777 { 10778 if (!Cp) 10779 break; 10780 } 10781 else 10782 { 10783 if (!cchMax) 10784 return VERR_END_OF_STRING; 10785 10786 psz[-1] = '?'; 10787 } 10788 } 10789 return VINF_SUCCESS; 10790 } 10791 10792 static int validateRemoteUSBDeviceDesc(VRDEUSBDEVICEDESC const *e, uint32_t cbRemaining, bool fDescExt) 10793 { 10794 uint32_t const cbDesc = fDescExt ? sizeof(VRDEUSBDEVICEDESCEXT) : sizeof(VRDEUSBDEVICEDESC); 10795 if (cbDesc > cbRemaining) 10796 return VERR_INVALID_PARAMETER; 10797 10798 if ( e->oNext > cbRemaining /* It is OK for oNext to point to the end of buffer. */ 10799 || e->oManufacturer >= cbRemaining 10800 || e->oProduct >= cbRemaining 10801 || e->oSerialNumber >= cbRemaining) 10802 return VERR_INVALID_PARAMETER; 10803 10804 int vrc; 10805 if (e->oManufacturer) 10806 { 10807 vrc = validateUtf8String((char *)e + e->oManufacturer, cbRemaining - e->oManufacturer); 10808 if (RT_FAILURE(vrc)) 10809 return VERR_INVALID_PARAMETER; 10810 } 10811 if (e->oProduct) 10812 { 10813 vrc = validateUtf8String((char *)e + e->oProduct, cbRemaining - e->oProduct); 10814 if (RT_FAILURE(vrc)) 10815 return VERR_INVALID_PARAMETER; 10816 } 10817 if (e->oSerialNumber) 10818 { 10819 vrc = validateUtf8String((char *)e + e->oSerialNumber, cbRemaining - e->oSerialNumber); 10820 if (RT_FAILURE(vrc)) 10821 return VERR_INVALID_PARAMETER; 10822 } 10823 10824 return VINF_SUCCESS; 10825 } 10826 10767 10827 /** 10768 10828 * @note Locks this object for writing. … … 10799 10859 * Process the pDevList and add devices those are not already in the mRemoteUSBDevices list. 10800 10860 */ 10801 /** @todo (sunlover) REMOTE_USB Strict validation of the pDevList. */10802 10861 VRDEUSBDEVICEDESC *e = pDevList; 10803 10804 /* The cbDevList condition must be checked first, because the function can 10862 uint32_t cbRemaining = cbDevList; 10863 10864 /* The cbRemaining condition must be checked first, because the function can 10805 10865 * receive pDevList = NULL and cbDevList = 0 on client disconnect. 10806 10866 */ 10807 while (cbDevList >= 2 && e->oNext) 10808 { 10809 /* Sanitize incoming strings in case they aren't valid UTF-8. */ 10810 if (e->oManufacturer) 10811 RTStrPurgeEncoding((char *)e + e->oManufacturer); 10812 if (e->oProduct) 10813 RTStrPurgeEncoding((char *)e + e->oProduct); 10814 if (e->oSerialNumber) 10815 RTStrPurgeEncoding((char *)e + e->oSerialNumber); 10867 while (cbRemaining >= sizeof(e->oNext) && e->oNext) 10868 { 10869 int const vrc = validateRemoteUSBDeviceDesc(e, cbRemaining, fDescExt); 10870 if (RT_FAILURE(vrc)) 10871 break; /* Consider the rest of the list invalid too. */ 10816 10872 10817 10873 LogFlowThisFunc(("vendor %04x, product %04x, name = %s\n", … … 10871 10927 } 10872 10928 10873 if (cbDevList < e->oNext) 10874 { 10875 Log1WarningThisFunc(("cbDevList %d > oNext %d\n", cbDevList, e->oNext)); 10876 break; 10877 } 10878 10879 cbDevList -= e->oNext; 10929 AssertBreak(cbRemaining >= e->oNext); /* validateRemoteUSBDeviceDesc ensures this. */ 10930 cbRemaining -= e->oNext; 10880 10931 10881 10932 e = (VRDEUSBDEVICEDESC *)((uint8_t *)e + e->oNext); -
trunk/src/VBox/Main/src-client/RemoteUSBBackend.cpp
r98278 r100521 1107 1107 RTMemFree(mpvDeviceList); 1108 1108 mpvDeviceList = NULL; 1109 1110 mcbDeviceList = cbList; 1109 mcbDeviceList = 0; 1111 1110 1112 1111 if (cbList > 0) 1113 1112 { 1114 1113 mpvDeviceList = RTMemAlloc(cbList); 1114 AssertPtrReturn(mpvDeviceList, VERR_NO_MEMORY); 1115 1115 1116 memcpy(mpvDeviceList, pvList, cbList); 1117 mcbDeviceList = cbList; 1116 1118 } 1117 1119 -
trunk/src/VBox/Main/src-client/RemoteUSBDeviceImpl.cpp
r98103 r100521 65 65 * Initializes the remote USB device object. 66 66 */ 67 HRESULT RemoteUSBDevice::init(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevDesc, bool fDescExt)67 HRESULT RemoteUSBDevice::init(uint32_t u32ClientId, VRDEUSBDEVICEDESC const *pDevDesc, bool fDescExt) 68 68 { 69 69 LogFlowThisFunc(("u32ClientId=%d,pDevDesc=%p\n", u32ClientId, pDevDesc));
Note:
See TracChangeset
for help on using the changeset viewer.