Changeset 81440 in vbox
- Timestamp:
- Oct 22, 2019 8:09:05 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 134158
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers.cpp
r81395 r81440 801 801 if (pTransfer->State.enmSource == SHCLSOURCE_LOCAL) 802 802 { 803 PSHCLOBJHANDLEINFO pInfo804 = (PSHCLOBJHANDLEINFO)RTMemAllocZ(sizeof(SHCLOBJHANDLEINFO));805 if (pInfo)806 {807 rc = ShClTransferObjHandleInfoInit(pInfo);808 if ( RT_SUCCESS(rc))803 /* 804 * Make sure the transfer direction matches the open/create parameters. 805 */ 806 if (pTransfer->State.enmDir == SHCLTRANSFERDIR_READ) 807 { 808 if (pOpenCreateParms->fCreate & SHCL_OBJ_CF_ACCESS_READ) /* Read access wanted? */ 809 809 { 810 /*811 * Make sure the transfer direction matches the open/create parameters.812 */813 if (pTransfer->State.enmDir == SHCLTRANSFERDIR_READ)814 {815 if (pOpenCreateParms->fCreate & SHCL_OBJ_CF_ACCESS_READ) /* Read access wanted? */816 817 AssertMsgFailed(("Is not a write transfer, but object open flags are set to read access (0x%x)\n",818 pOpenCreateParms->fCreate)); /* Should never happen. */819 rc = VERR_INVALID_PARAMETER;820 }821 }822 else if (pTransfer->State.enmDir == SHCLTRANSFERDIR_WRITE)823 {824 if (pOpenCreateParms->fCreate & SHCL_OBJ_CF_ACCESS_WRITE) /* Write access wanted? */825 826 AssertMsgFailed(("Is not a read transfer, but object open flags are set to write access (0x%x)\n",827 pOpenCreateParms->fCreate)); /* Should never happen. */828 rc = VERR_INVALID_PARAMETER;829 } 830 }831 else832 {833 AssertFailed();834 rc = VERR_NOT_SUPPORTED;835 }836 810 AssertMsgFailed(("Is not a write transfer, but object open flags are set to read access (0x%x)\n", 811 pOpenCreateParms->fCreate)); /* Should never happen. */ 812 rc = VERR_INVALID_PARAMETER; 813 } 814 } 815 else if (pTransfer->State.enmDir == SHCLTRANSFERDIR_WRITE) 816 { 817 if (pOpenCreateParms->fCreate & SHCL_OBJ_CF_ACCESS_WRITE) /* Write access wanted? */ 818 { 819 AssertMsgFailed(("Is not a read transfer, but object open flags are set to write access (0x%x)\n", 820 pOpenCreateParms->fCreate)); /* Should never happen. */ 821 rc = VERR_INVALID_PARAMETER; 822 } 823 } 824 else 825 { 826 AssertFailed(); 827 rc = VERR_NOT_SUPPORTED; 828 } 829 830 if (RT_SUCCESS(rc)) 831 { 832 PSHCLOBJHANDLEINFO pInfo 833 = (PSHCLOBJHANDLEINFO)RTMemAllocZ(sizeof(SHCLOBJHANDLEINFO)); 834 if (pInfo) 835 { 836 rc = ShClTransferObjHandleInfoInit(pInfo); 837 837 if (RT_SUCCESS(rc)) 838 838 { 839 839 840 /* Only if this is a read transfer (locally) we're able to actually write to files 840 841 * (we're reading from the source). */ … … 847 848 if (RT_SUCCESS(rc)) 848 849 { 849 rc = shClTransferResolvePathAbs(pTransfer, pOpenCreateParms->pszPath, 0 /* fFlags */, &pInfo->pszPathLocalAbs); 850 rc = shClTransferResolvePathAbs(pTransfer, pOpenCreateParms->pszPath, 0 /* fFlags */, 851 &pInfo->pszPathLocalAbs); 850 852 if (RT_SUCCESS(rc)) 851 853 { … … 860 862 } 861 863 } 862 } 863 864 if (RT_SUCCESS(rc)) 865 { 866 pInfo->hObj = pTransfer->uObjHandleNext++; 867 pInfo->enmType = SHCLOBJTYPE_FILE; 868 869 RTListAppend(&pTransfer->lstObj, &pInfo->Node); 870 pTransfer->cObjHandles++; 871 872 LogFlowFunc(("cObjHandles=%RU32\n", pTransfer->cObjHandles)); 873 874 *phObj = pInfo->hObj; 864 865 if (RT_SUCCESS(rc)) 866 { 867 pInfo->hObj = pTransfer->uObjHandleNext++; 868 pInfo->enmType = SHCLOBJTYPE_FILE; 869 870 RTListAppend(&pTransfer->lstObj, &pInfo->Node); 871 pTransfer->cObjHandles++; 872 873 LogFlowFunc(("cObjHandles=%RU32\n", pTransfer->cObjHandles)); 874 875 *phObj = pInfo->hObj; 876 } 877 else 878 { 879 ShClTransferObjHandleInfoDestroy(pInfo); 880 RTMemFree(pInfo); 881 } 875 882 } 876 883 else 877 { 878 ShClTransferObjHandleInfoDestroy(pInfo); 879 RTMemFree(pInfo); 880 } 881 } 882 else 883 rc = VERR_NO_MEMORY; 884 rc = VERR_NO_MEMORY; 885 } 884 886 } 885 887 else if (pTransfer->State.enmSource == SHCLSOURCE_REMOTE) … … 892 894 rc = VERR_NOT_SUPPORTED; 893 895 } 896 else 897 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED); 894 898 895 899 LogFlowFuncLeaveRC(rc); … … 972 976 rc = VERR_NOT_SUPPORTED; 973 977 } 978 else 979 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED); 974 980 975 981 LogFlowFuncLeaveRC(rc); … … 1034 1040 rc = VERR_NOT_SUPPORTED; 1035 1041 } 1042 else 1043 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED); 1036 1044 1037 1045 LogFlowFuncLeaveRC(rc); … … 1090 1098 rc = VERR_NOT_SUPPORTED; 1091 1099 } 1100 else 1101 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED); 1092 1102 1093 1103 LogFlowFuncLeaveRC(rc); … … 1369 1379 1370 1380 /** 1381 * Valides whether a given path matches our set of rules or not. 1382 * 1383 * @returns VBox status code. 1384 * @param pszPath Path to validate. 1385 * @param fMustExist Whether the path to validate also must exist. 1386 */ 1387 static int shClTransferValidatePath(const char *pszPath, bool fMustExist) 1388 { 1389 int rc = VINF_SUCCESS; 1390 1391 if (!strlen(pszPath)) 1392 rc = VERR_INVALID_PARAMETER; 1393 1394 if ( RT_SUCCESS(rc) 1395 && !RTStrIsValidEncoding(pszPath)) 1396 { 1397 rc = VERR_INVALID_UTF8_ENCODING; 1398 } 1399 1400 if ( RT_SUCCESS(rc) 1401 && RTStrStr(pszPath, "..")) 1402 { 1403 rc = VERR_INVALID_PARAMETER; 1404 } 1405 1406 if ( RT_SUCCESS(rc) 1407 && fMustExist) 1408 { 1409 RTFSOBJINFO objInfo; 1410 rc = RTPathQueryInfo(pszPath, &objInfo, RTFSOBJATTRADD_NOTHING); 1411 if (RT_SUCCESS(rc)) 1412 { 1413 if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode)) 1414 { 1415 if (!RTDirExists(pszPath)) /* Path must exist. */ 1416 rc = VERR_PATH_NOT_FOUND; 1417 } 1418 else if (RTFS_IS_FILE(objInfo.Attr.fMode)) 1419 { 1420 if (!RTFileExists(pszPath)) /* File must exist. */ 1421 rc = VERR_FILE_NOT_FOUND; 1422 } 1423 else /* Everything else (e.g. symbolic links) are not supported. */ 1424 rc = VERR_NOT_SUPPORTED; 1425 } 1426 } 1427 1428 LogFlowFuncLeaveRC(rc); 1429 return rc; 1430 } 1431 1432 /** 1371 1433 * Resolves a relative path of a specific transfer to its absolute path. 1372 1434 * … … 1386 1448 LogFlowFunc(("pszPathRootAbs=%s, pszPath=%s\n", pTransfer->pszPathRootAbs, pszPath)); 1387 1449 1388 /* Paranoia. */ 1389 if ( !strlen(pszPath) 1390 || !RTStrIsValidEncoding(pszPath) 1391 || RTStrStr(pszPath, "..")) 1392 { 1393 LogRel(("Shared Clipboard: Resolving absolute path '%s' failed, invalid\n", pszPath)); 1394 return VERR_INVALID_PARAMETER; 1395 } 1396 1397 int rc; 1398 1399 char *pszResolved = RTPathJoinA(pTransfer->pszPathRootAbs, pszPath); 1400 if (pszResolved) 1401 { 1402 LogFlowFunc(("Resolved to: %s\n", pszResolved)); 1403 1404 *ppszResolved = pszResolved; 1405 1406 rc = VINF_SUCCESS; 1407 } 1408 else 1409 rc = VERR_NO_MEMORY; 1450 int rc = shClTransferValidatePath(pszPath, false /* fMustExist */); 1451 if (RT_SUCCESS(rc)) 1452 { 1453 char *pszPathAbs = RTPathJoinA(pTransfer->pszPathRootAbs, pszPath); 1454 if (pszPathAbs) 1455 { 1456 char szResolved[RTPATH_MAX + 1]; 1457 size_t cbResolved = sizeof(szResolved); 1458 rc = RTPathAbsEx(pTransfer->pszPathRootAbs, pszPathAbs, RTPATH_STR_F_STYLE_HOST, szResolved, &cbResolved); 1459 1460 RTStrFree(pszPathAbs); 1461 1462 if (RT_SUCCESS(rc)) 1463 { 1464 LogFlowFunc(("pszResolved=%s\n", szResolved)); 1465 1466 rc = VERR_PATH_NOT_FOUND; /* Play safe by default. */ 1467 1468 /* Make sure the resolved path is part of the set of root entries. */ 1469 PSHCLLISTROOT pListRoot; 1470 RTListForEach(&pTransfer->lstRoots, pListRoot, SHCLLISTROOT, Node) 1471 { 1472 if (RTPathStartsWith(szResolved, pListRoot->pszPathAbs)) 1473 { 1474 rc = VINF_SUCCESS; 1475 break; 1476 } 1477 } 1478 1479 if (RT_SUCCESS(rc)) 1480 *ppszResolved = RTStrDup(szResolved); 1481 } 1482 } 1483 else 1484 rc = VERR_NO_MEMORY; 1485 } 1486 1487 if (RT_FAILURE(rc)) 1488 LogRel(("Shared Clipboard: Resolving absolute path '%s' failed, rc=%Rrc\n", pszPath, rc)); 1410 1489 1411 1490 LogFlowFuncLeaveRC(rc); … … 1441 1520 if (pInfo) 1442 1521 { 1443 rc = shClTransferResolvePathAbs(pTransfer, pOpenParms->pszPath, 0 /* fFlags */, &pInfo->pszPathLocalAbs);1522 rc = ShClTransferListHandleInfoInit(pInfo); 1444 1523 if (RT_SUCCESS(rc)) 1445 1524 { 1446 rc = ShClTransferListHandleInfoInit(pInfo);1525 rc = shClTransferResolvePathAbs(pTransfer, pOpenParms->pszPath, 0 /* fFlags */, &pInfo->pszPathLocalAbs); 1447 1526 if (RT_SUCCESS(rc)) 1448 1527 { … … 1486 1565 RTListAppend(&pTransfer->lstList, &pInfo->Node); 1487 1566 pTransfer->cListHandles++; 1567 1568 if (phList) 1569 *phList = pInfo->hList; 1488 1570 1489 1571 LogFlowFunc(("pszPathLocalAbs=%s, hList=%RU64, cListHandles=%RU32\n", … … 1947 2029 rc = VERR_NOT_SUPPORTED; 1948 2030 } 2031 else 2032 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED); 1949 2033 1950 2034 LogFlowFuncLeaveRC(rc); … … 1987 2071 AssertFailed(); /** @todo Implement. */ 1988 2072 } 2073 else 2074 AssertFailedStmt(fIsValid = false); 1989 2075 1990 2076 return fIsValid; … … 2246 2332 rc = VERR_NOT_SUPPORTED; 2247 2333 } 2334 else 2335 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED); 2248 2336 2249 2337 LogFlowFuncLeaveRC(rc); 2250 2338 return rc; 2251 2339 } 2252 2253 2340 2254 2341 /** … … 2282 2369 AssertPtrBreakStmt(pListRoot, rc = VERR_NO_MEMORY); 2283 2370 2284 pListRoot->pszPathAbs = RTStrDup(lstRootEntries.at(i).c_str()); 2285 AssertPtrBreakStmt(pListRoot->pszPathAbs, rc = VERR_NO_MEMORY); 2286 2371 const char *pszPathCur = RTStrDup(lstRootEntries.at(i).c_str()); 2372 2373 LogFlowFunc(("pszPathCur=%s\n", pszPathCur)); 2374 2375 /* No root path determined yet? */ 2287 2376 if (!pszPathRootAbs) 2288 2377 { 2289 pszPathRootAbs = RTStrDup(p ListRoot->pszPathAbs);2378 pszPathRootAbs = RTStrDup(pszPathCur); 2290 2379 if (pszPathRootAbs) 2291 2380 { 2292 2381 RTPathStripFilename(pszPathRootAbs); 2382 2293 2383 LogFlowFunc(("pszPathRootAbs=%s\n", pszPathRootAbs)); 2384 2385 /* We don't want to have a relative directory here. */ 2386 if (RTPathStartsWithRoot(pszPathRootAbs)) 2387 { 2388 rc = shClTransferValidatePath(pszPathRootAbs, true /* Path must exist */); 2389 } 2390 else 2391 rc = VERR_INVALID_PARAMETER; 2294 2392 } 2295 2393 else … … 2300 2398 break; 2301 2399 2302 /* Make sure all entries have the same root path. */2303 if (! RTStrStartsWith(pListRoot->pszPathAbs, pszPathRootAbs))2304 { 2305 rc = VERR_ INVALID_PARAMETER;2400 pListRoot->pszPathAbs = RTStrDup(pszPathCur); 2401 if (!pListRoot->pszPathAbs) 2402 { 2403 rc = VERR_NO_MEMORY; 2306 2404 break; 2307 2405 } … … 2310 2408 2311 2409 pTransfer->cRoots++; 2410 } 2411 2412 /* No (valid) root directory found? Bail out early. */ 2413 if (!pszPathRootAbs) 2414 rc = VERR_PATH_NOT_FOUND; 2415 2416 if (RT_SUCCESS(rc)) 2417 { 2418 /* 2419 * Step 2: 2420 * Go through the created list and make sure all entries have the same root path. 2421 */ 2422 PSHCLLISTROOT pListRoot; 2423 RTListForEach(&pTransfer->lstRoots, pListRoot, SHCLLISTROOT, Node) 2424 { 2425 if (!RTStrStartsWith(pListRoot->pszPathAbs, pszPathRootAbs)) 2426 { 2427 rc = VERR_INVALID_PARAMETER; 2428 break; 2429 } 2430 2431 rc = shClTransferValidatePath(pListRoot->pszPathAbs, true /* Path must exist */); 2432 if (RT_FAILURE(rc)) 2433 break; 2434 } 2312 2435 } 2313 2436 … … 2322 2445 } 2323 2446 else 2447 { 2324 2448 LogRel(("Shared Clipboard: Unable to set roots for transfer, rc=%Rrc\n", rc)); 2449 RTStrFree(pszPathRootAbs); 2450 } 2325 2451 2326 2452 LogFlowFuncLeaveRC(rc);
Note:
See TracChangeset
for help on using the changeset viewer.