- Timestamp:
- Jul 11, 2014 9:04:44 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/shflsvc.h
r51254 r51997 153 153 * Shared folder string buffer structure. 154 154 */ 155 #pragma pack(1) 155 156 typedef struct _SHFLSTRING 156 157 { 157 /** Size of the String member in bytes. */158 /** Allocated size of the String member in bytes. */ 158 159 uint16_t u16Size; 159 160 … … 168 169 } String; 169 170 } SHFLSTRING; 171 #pragma pack() 172 173 #define SHFLSTRING_HEADER_SIZE RT_UOFFSETOF(SHFLSTRING, String) 174 AssertCompile(SHFLSTRING_HEADER_SIZE == 4); 170 175 171 176 /** Pointer to a shared folder string buffer. */ … … 188 193 { 189 194 PSHFLSTRING pString = NULL; 190 const uint32_t u32HeaderSize = sizeof(SHFLSTRING);195 const uint32_t u32HeaderSize = SHFLSTRING_HEADER_SIZE; 191 196 192 197 /* … … 199 204 pString->u16Size = u32Size - u32HeaderSize; 200 205 pString->u16Length = 0; 206 if (pString->u16Size >= sizeof(pString->String.ucs2[0])) 207 pString->String.ucs2[0] = 0; 208 else if (pString->u16Size >= sizeof(pString->String.utf8[0])) 209 pString->String.utf8[0] = 0; 201 210 } 202 211 -
trunk/src/VBox/Additions/WINNT/SharedFolders/driver/info.c
r51254 r51997 113 113 if (Template->Length) 114 114 { 115 ULONG ParsedPathSize, len; 116 117 /* Calculate length required for parsed path. */ 118 ParsedPathSize = sizeof(SHFLSTRING) + DirectoryName->Length + Template->Length + 3 * sizeof(WCHAR); 115 ULONG ParsedPathSize, cch; 116 117 /* Calculate size required for parsed path: dir + \ + template + 0. */ 118 ParsedPathSize = SHFLSTRING_HEADER_SIZE + Template->Length + sizeof(WCHAR); 119 if (DirectoryName->Length) 120 ParsedPathSize += DirectoryName->Length + sizeof(WCHAR); 119 121 Log(("VBOXSF: MrxQueryDirectory: ParsedPathSize = %d\n", ParsedPathSize)); 120 122 … … 126 128 } 127 129 128 RtlZeroMemory(ParsedPath, ParsedPathSize);129 130 if (!ShflStringInitBuffer(ParsedPath, ParsedPathSize)) 130 131 { … … 133 134 } 134 135 135 ParsedPath->u16Size = DirectoryName->Length + Template->Length + sizeof(WCHAR); 136 ParsedPath->u16Length = ParsedPath->u16Size - sizeof(WCHAR); /* Without terminating null. */ 137 138 len = 0; 136 cch = 0; 139 137 if (DirectoryName->Length) 140 138 { 141 139 /* Copy directory name into ParsedPath. */ 142 140 RtlCopyMemory(ParsedPath->String.ucs2, DirectoryName->Buffer, DirectoryName->Length); 143 len= DirectoryName->Length / sizeof(WCHAR);141 cch += DirectoryName->Length / sizeof(WCHAR); 144 142 145 143 /* Add terminating backslash. */ 146 ParsedPath->String.ucs2[len] = L'\\'; 147 len++; 148 ParsedPath->u16Length += sizeof(WCHAR); 149 ParsedPath->u16Size += sizeof(WCHAR); 150 } 151 RtlCopyMemory (&ParsedPath->String.ucs2[len], Template->Buffer, Template->Length); 144 ParsedPath->String.ucs2[cch] = L'\\'; 145 cch++; 146 } 147 148 RtlCopyMemory (&ParsedPath->String.ucs2[cch], Template->Buffer, Template->Length); 149 cch += Template->Length / sizeof(WCHAR); 150 151 /* Add terminating nul. */ 152 ParsedPath->String.ucs2[cch] = 0; 153 154 /* cch is the number of chars without trailing nul. */ 155 ParsedPath->u16Length = (uint16_t)(cch * sizeof(WCHAR)); 156 157 AssertMsg(ParsedPath->u16Length + sizeof(WCHAR) == ParsedPath->u16Size, 158 ("u16Length %d, u16Size %d\n", ParsedPath->u16Length, ParsedPath->u16Size)); 152 159 153 160 Log(("VBOXSF: MrxQueryDirectory: ParsedPath = %.*ls\n", -
trunk/src/VBox/Additions/WINNT/SharedFolders/driver/net.c
r51254 r51997 169 169 int vboxRC; 170 170 PSHFLSTRING ParsedPath = 0; 171 ULONG ParsedPathSize;172 171 173 172 Log(("VBOXSF: MRxCreateVNetRoot: initialize NET_ROOT\n")); … … 200 199 RootNameLength, RootNameLength / sizeof(WCHAR), pRootName)); 201 200 202 /* Calculate the length required for parsed path. */ 203 ParsedPathSize = sizeof(SHFLSTRING) + RootNameLength + sizeof(WCHAR); 204 ParsedPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize); 205 if (!ParsedPath) 201 Status = vbsfShflStringFromUnicodeAlloc(&ParsedPath, pRootName, (uint16_t)RootNameLength); 202 if (Status != STATUS_SUCCESS) 206 203 { 207 Status = STATUS_INSUFFICIENT_RESOURCES;208 204 goto l_Exit; 209 205 } 210 memset(ParsedPath, 0, ParsedPathSize);211 if (!ShflStringInitBuffer(ParsedPath, ParsedPathSize))212 {213 vbsfFreeNonPagedMem(ParsedPath);214 Status = STATUS_INSUFFICIENT_RESOURCES;215 goto l_Exit;216 }217 ParsedPath->u16Length = ParsedPath->u16Size - sizeof(WCHAR); /* without terminating null */218 RtlCopyMemory(ParsedPath->String.ucs2, pRootName, ParsedPath->u16Length);219 206 220 207 vboxRC = vboxCallMapFolder(&pDeviceExtension->hgcmClient, ParsedPath, &pNetRootExtension->map); -
trunk/src/VBox/Additions/WINNT/SharedFolders/driver/path.c
r51254 r51997 248 248 { 249 249 PSHFLSTRING ParsedPath; 250 ULONG ParsedPathSize; 251 252 /* Calculate length required for parsed path. 253 */ 254 ParsedPathSize = sizeof(*ParsedPath) + (RemainingName->Length + sizeof(WCHAR)); 255 Log(("VBOXSF: vbsfProcessCreate: ParsedPathSize = %d\n", ParsedPathSize)); 256 257 ParsedPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize); 258 if (!ParsedPath) 250 Log(("VBOXSF: vbsfProcessCreate: RemainingName->Length = %d\n", RemainingName->Length)); 251 252 Status = vbsfShflStringFromUnicodeAlloc(&ParsedPath, RemainingName->Buffer, RemainingName->Length); 253 if (Status != STATUS_SUCCESS) 259 254 { 260 Status = STATUS_INSUFFICIENT_RESOURCES;261 255 goto failure; 262 256 } 263 257 264 if (!ShflStringInitBuffer(ParsedPath, ParsedPathSize))265 {266 vbsfFreeNonPagedMem(ParsedPath);267 Status = STATUS_INSUFFICIENT_RESOURCES;268 goto failure;269 }270 271 ParsedPath->u16Length = ParsedPath->u16Size - sizeof(WCHAR); /* without terminating null */272 RtlCopyMemory (ParsedPath->String.ucs2, RemainingName->Buffer, ParsedPath->u16Length);273 258 Log(("VBOXSF: ParsedPath: %.*ls\n", 274 259 ParsedPath->u16Length / sizeof(WCHAR), ParsedPath->String.ucs2)); … … 839 824 int vboxRC; 840 825 PSHFLSTRING ParsedPath = NULL; 841 ULONG ParsedPathSize;842 826 843 827 Log(("VBOXSF: vbsfRemove: Delete %.*ls. open count = %d\n", … … 848 832 vbsfCloseFileHandle(pDeviceExtension, pNetRootExtension, pVBoxFobx); 849 833 850 /* Calculate length required for parsed path. */ 851 ParsedPathSize = sizeof(SHFLSTRING) + RemainingName->Length + sizeof(WCHAR); 852 Log(("VBOXSF: vbsfRemove: ParsedPathSize %d\n", ParsedPathSize)); 853 854 ParsedPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize); 855 if (!ParsedPath) 856 return STATUS_INSUFFICIENT_RESOURCES; 857 858 if (!ShflStringInitBuffer(ParsedPath, ParsedPathSize)) 859 { 860 vbsfFreeNonPagedMem(ParsedPath); 861 return STATUS_INSUFFICIENT_RESOURCES; 862 } 863 864 Log(("VBOXSF: vbsfRemove: Setup ParsedPath\n")); 865 ParsedPath->u16Length = ParsedPath->u16Size - sizeof(WCHAR); /* without terminating null */ 866 RtlCopyMemory(ParsedPath->String.ucs2, RemainingName->Buffer, ParsedPath->u16Length); 834 Log(("VBOXSF: vbsfRemove: RemainingName->Length %d\n", RemainingName->Length)); 835 Status = vbsfShflStringFromUnicodeAlloc(&ParsedPath, RemainingName->Buffer, RemainingName->Length); 836 if (Status != STATUS_SUCCESS) 837 return Status; 867 838 868 839 /* Call host. */ … … 905 876 int vboxRC; 906 877 PSHFLSTRING SrcPath = 0, DestPath = 0; 907 ULONG ParsedPathSize,flags;878 ULONG flags; 908 879 909 880 Assert(FileInformationClass == FileRenameInformation); … … 919 890 SetFlag(pSrvOpen->Flags, SRVOPEN_FLAG_FILE_RENAMED); 920 891 921 /* Calculate length required for destination path. */ 922 ParsedPathSize = sizeof(SHFLSTRING) + RenameInformation->FileNameLength + sizeof(WCHAR); 923 Log(("VBOXSF: vbsfRename: ParsedPathSize = %d\n", ParsedPathSize)); 924 925 DestPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize); 926 if (!DestPath) 927 return STATUS_INSUFFICIENT_RESOURCES; 928 929 RtlZeroMemory(DestPath, ParsedPathSize); 930 if (!ShflStringInitBuffer(DestPath, ParsedPathSize)) 931 { 932 vbsfFreeNonPagedMem(DestPath); 933 return STATUS_INSUFFICIENT_RESOURCES; 934 } 935 936 Log(("VBOXSF: vbsfRename: Setting up destination path\n")); 937 DestPath->u16Length = DestPath->u16Size - sizeof(WCHAR); /* without terminating null */ 938 RtlCopyMemory(DestPath->String.ucs2, RenameInformation->FileName, DestPath->u16Length); 892 Log(("VBOXSF: vbsfRename: RenameInformation->FileNameLength = %d\n", RenameInformation->FileNameLength)); 893 Status = vbsfShflStringFromUnicodeAlloc(&DestPath, RenameInformation->FileName, (uint16_t)RenameInformation->FileNameLength); 894 if (Status != STATUS_SUCCESS) 895 return Status; 939 896 940 897 Log(("VBOXSF: vbsfRename: Destination path = %.*ls\n", 941 898 DestPath->u16Length / sizeof(WCHAR), &DestPath->String.ucs2[0])); 942 899 943 /* Calculate length required for source path */ 944 ParsedPathSize = sizeof(*DestPath) + (RemainingName->Length + sizeof(WCHAR)); 945 946 Log(("VBOXSF: vbsfRename: ParsedPathSize = %d\n", ParsedPathSize)); 947 948 SrcPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize); 949 if (!SrcPath) 900 Log(("VBOXSF: vbsfRename: RemainingName->Length = %d\n", RemainingName->Length)); 901 Status = vbsfShflStringFromUnicodeAlloc(&SrcPath, RemainingName->Buffer, RemainingName->Length); 902 if (Status != STATUS_SUCCESS) 950 903 { 951 904 vbsfFreeNonPagedMem(DestPath); 952 return STATUS_INSUFFICIENT_RESOURCES; 953 } 954 955 RtlZeroMemory(SrcPath, ParsedPathSize); 956 if (!ShflStringInitBuffer(SrcPath, ParsedPathSize)) 957 { 958 vbsfFreeNonPagedMem(DestPath); 959 vbsfFreeNonPagedMem(SrcPath); 960 return STATUS_INSUFFICIENT_RESOURCES; 961 } 962 963 Log(("VBOXSF: vbsfRename: Setting up source path\n")); 964 965 SrcPath->u16Length = SrcPath->u16Size - sizeof(WCHAR); /* without terminating null */ 966 RtlCopyMemory(SrcPath->String.ucs2, RemainingName->Buffer, SrcPath->u16Length); 905 return Status; 906 } 967 907 968 908 Log(("VBOXSF: vbsfRename: Source path = %.*ls\n", -
trunk/src/VBox/Additions/WINNT/SharedFolders/driver/vbsf.c
r51254 r51997 663 663 } 664 664 665 if (cbOut >= _MRX_MAX_DRIVE_LETTERS && !pu8Out)665 if (cbOut >= _MRX_MAX_DRIVE_LETTERS && pu8Out) 666 666 { 667 667 BOOLEAN fLocked = FALSE; … … 706 706 break; 707 707 708 if (cbOut >= _MRX_MAX_DRIVE_LETTERS && !pu8Out)708 if (cbOut >= _MRX_MAX_DRIVE_LETTERS && pu8Out) 709 709 { 710 710 SHFLMAPPING mappings[_MRX_MAX_DRIVE_LETTERS]; … … 762 762 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: Looking up connection name and connections\n")); 763 763 764 if (cbConnectName > sizeof(WCHAR) && !pwcConnectName)764 if (cbConnectName > sizeof(WCHAR) && pwcConnectName) 765 765 { 766 766 ULONG cbLocalConnectionName; … … 829 829 int vboxRC; 830 830 PSHFLSTRING pString; 831 uint32_t cbString;832 831 833 832 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALCONN: Connection ID = %d, RemoteName = 0x%x, Len = %d\n", 834 833 *pConnectId, pwcRemoteName, cbRemoteName)); 835 834 836 cbString = sizeof(SHFLSTRING) + cbRemoteName; 837 pString = (PSHFLSTRING)vbsfAllocNonPagedMem(cbString); 838 if (!pString) 839 { 840 Status = STATUS_INSUFFICIENT_RESOURCES; 835 /* Allocate empty string where the host can store cbRemoteName bytes. */ 836 Status = vbsfShflStringFromUnicodeAlloc(&pString, NULL, (uint16_t)cbRemoteName); 837 if (Status != STATUS_SUCCESS) 841 838 break; 842 }843 memset(pString, 0, cbString);844 if (!ShflStringInitBuffer(pString, cbString))845 {846 vbsfFreeNonPagedMem(pString);847 Status = STATUS_BAD_NETWORK_NAME;848 break;849 }850 839 851 840 vboxRC = vboxCallQueryMapName(&pDeviceExtension->hgcmClient, 852 841 (*pConnectId) & ~0x80 /** @todo fix properly */, 853 pString, cbString);842 pString, ShflStringSizeOfBuffer(pString)); 854 843 if ( vboxRC == VINF_SUCCESS 855 844 && pString->u16Length < cbRemoteName) -
trunk/src/VBox/Additions/WINNT/SharedFolders/driver/vbsfhlp.c
r40986 r51997 434 434 } 435 435 #endif 436 437 /** Allocate and initialize a SHFLSTRING from a UNICODE string. 438 * 439 * @param ppShflString Where to store the pointer to the allocated SHFLSTRING structure. 440 * The structure must be deallocated with vbsfFreeNonPagedMem. 441 * @param pwc The UNICODE string. If NULL then SHFL is only allocated. 442 * @param cb Size of the UNICODE string in bytes without the trailing nul. 443 * 444 * @return Status code. 445 */ 446 NTSTATUS vbsfShflStringFromUnicodeAlloc(PSHFLSTRING *ppShflString, const WCHAR *pwc, uint16_t cb) 447 { 448 NTSTATUS Status = STATUS_SUCCESS; 449 450 PSHFLSTRING pShflString; 451 ULONG ulShflStringSize; 452 453 /* Calculate length required for the SHFL structure: header + chars + nul. */ 454 ulShflStringSize = SHFLSTRING_HEADER_SIZE + cb + sizeof(WCHAR); 455 pShflString = (PSHFLSTRING)vbsfAllocNonPagedMem(ulShflStringSize); 456 if (pShflString) 457 { 458 if (ShflStringInitBuffer(pShflString, ulShflStringSize)) 459 { 460 if (pwc) 461 { 462 RtlCopyMemory(pShflString->String.ucs2, pwc, cb); 463 pShflString->String.ucs2[cb / sizeof(WCHAR)] = 0; 464 pShflString->u16Length = cb; /* without terminating null */ 465 AssertMsg(pShflString->u16Length + sizeof(WCHAR) == pShflString->u16Size, 466 ("u16Length %d, u16Size %d\n", pShflString->u16Length, pShflString->u16Size)); 467 } 468 else 469 { 470 RtlZeroMemory(pShflString->String.ucs2, cb + sizeof(WCHAR)); 471 pShflString->u16Length = 0; /* without terminating null */ 472 AssertMsg(pShflString->u16Size >= sizeof(WCHAR), 473 ("u16Size %d\n", pShflString->u16Size)); 474 } 475 476 *ppShflString = pShflString; 477 } 478 else 479 { 480 vbsfFreeNonPagedMem(pShflString); 481 Status = STATUS_INSUFFICIENT_RESOURCES; 482 } 483 } 484 else 485 { 486 Status = STATUS_INSUFFICIENT_RESOURCES; 487 } 488 489 return Status; 490 } -
trunk/src/VBox/Additions/WINNT/SharedFolders/driver/vbsfhlp.h
r40319 r51997 63 63 #endif 64 64 65 NTSTATUS vbsfShflStringFromUnicodeAlloc(PSHFLSTRING *ppShflString, const WCHAR *pwc, uint16_t cb); 66 65 67 #endif /* __VBSFHLP__H */ -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibSharedFolders.cpp
r51254 r51997 245 245 246 246 int rc; 247 uint32_t cbString = sizeof(SHFLSTRING)+ SHFL_MAX_LEN;247 uint32_t cbString = SHFLSTRING_HEADER_SIZE + SHFL_MAX_LEN; 248 248 PSHFLSTRING pString = (PSHFLSTRING)RTMemAlloc(cbString); 249 249 if (pString) 250 250 { 251 RT_ZERO(*pString); 252 if (!ShflStringInitBuffer(pString, SHFL_MAX_LEN)) 251 if (!ShflStringInitBuffer(pString, cbString)) 253 252 { 254 253 RTMemFree(pString); -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r51925 r51997 7837 7837 if (cbString >= UINT16_MAX) 7838 7838 return setError(E_INVALIDARG, tr("The name is too long")); 7839 pFolderName = (SHFLSTRING*)RTMemAllocZ( sizeof(SHFLSTRING)+ cbString);7839 pFolderName = (SHFLSTRING*)RTMemAllocZ(SHFLSTRING_HEADER_SIZE + cbString); 7840 7840 Assert(pFolderName); 7841 7841 memcpy(pFolderName->String.ucs2, bstrHostPath.raw(), cbString); … … 7846 7846 parms[0].type = VBOX_HGCM_SVC_PARM_PTR; 7847 7847 parms[0].u.pointer.addr = pFolderName; 7848 parms[0].u.pointer.size = sizeof(SHFLSTRING) + (uint16_t)cbString;7848 parms[0].u.pointer.size = ShflStringSizeOfBuffer(pFolderName); 7849 7849 7850 7850 cbString = (bstrName.length() + 1) * sizeof(RTUTF16); … … 7854 7854 return setError(E_INVALIDARG, tr("The host path is too long")); 7855 7855 } 7856 pMapName = (SHFLSTRING*)RTMemAllocZ( sizeof(SHFLSTRING)+ cbString);7856 pMapName = (SHFLSTRING*)RTMemAllocZ(SHFLSTRING_HEADER_SIZE + cbString); 7857 7857 Assert(pMapName); 7858 7858 memcpy(pMapName->String.ucs2, bstrName.raw(), cbString); … … 7863 7863 parms[1].type = VBOX_HGCM_SVC_PARM_PTR; 7864 7864 parms[1].u.pointer.addr = pMapName; 7865 parms[1].u.pointer.size = sizeof(SHFLSTRING) + (uint16_t)cbString;7865 parms[1].u.pointer.size = ShflStringSizeOfBuffer(pMapName); 7866 7866 7867 7867 parms[2].type = VBOX_HGCM_SVC_PARM_32BIT; … … 7917 7917 if (cbString >= UINT16_MAX) 7918 7918 return setError(E_INVALIDARG, tr("The name is too long")); 7919 pMapName = (SHFLSTRING *) RTMemAllocZ( sizeof(SHFLSTRING)+ cbString);7919 pMapName = (SHFLSTRING *) RTMemAllocZ(SHFLSTRING_HEADER_SIZE + cbString); 7920 7920 Assert(pMapName); 7921 7921 memcpy(pMapName->String.ucs2, bstrName.raw(), cbString); … … 7926 7926 parms.type = VBOX_HGCM_SVC_PARM_PTR; 7927 7927 parms.u.pointer.addr = pMapName; 7928 parms.u.pointer.size = sizeof(SHFLSTRING) + (uint16_t)cbString;7928 parms.u.pointer.size = ShflStringSizeOfBuffer(pMapName); 7929 7929 7930 7930 int vrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders",
Note:
See TracChangeset
for help on using the changeset viewer.