Changeset 85002 in vbox
- Timestamp:
- Jun 30, 2020 9:34:16 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 138900
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/GuestHost/DragAndDrop.h
r84998 r85002 95 95 bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax); 96 96 97 int DnDPathValidate(const char *pcszPath, bool fMustExist); 98 99 /** DnD path conversion flags. */ 100 typedef uint32_t DNDPATHCONVERTFLAGS; 101 102 /** No flags specified. 103 * This also will convert the path to the universal tansport style. */ 104 #define DNDPATHCONVERT_FLAGS_NONE 0 105 /** Converts the path to a OS-dependent path. */ 106 #define DNDPATHCONVERT_FLAGS_TO_NATIVE RT_BIT(0) 107 108 /** Mask of all valid DnD path conversion flags. */ 109 #define DNDPATHCONVERT_FLAGS_VALID_MASK UINT32_C(0x1) 110 111 int DnDPathConvert(char *pszPath, size_t cbPath, DNDPATHCONVERTFLAGS fFlags); 97 112 int DnDPathSanitizeFilename(char *pszPath, size_t cbPath); 98 int DnDPathSanitize(char *pszPath, size_t cbPath);99 113 100 114 /** DnDURIObject flags. */ -
trunk/src/VBox/GuestHost/DragAndDrop/DnDPath.cpp
r82968 r85002 23 23 #include <VBox/GuestHost/DragAndDrop.h> 24 24 25 #include <iprt/dir.h> 25 26 #include <iprt/err.h> 27 #include <iprt/file.h> 26 28 #include <iprt/path.h> 27 29 #include <iprt/string.h> … … 55 57 '\0' 56 58 }; 57 ssize_t cReplaced = RTStrPurgeComplementSet(pszPath, s_uszValidRangePairs, '_' /* chReplacement */); 58 if (cReplaced < 0) 59 rc = VERR_INVALID_UTF8_ENCODING; 59 char *pszFilename = RTPathFilename(pszPath); 60 if (pszFilename) 61 { 62 ssize_t cReplaced = RTStrPurgeComplementSet(, s_uszValidRangePairs, '_' /* chReplacement */); 63 if (cReplaced < 0) 64 rc = VERR_INVALID_UTF8_ENCODING; 65 } 66 else 67 rc = VERR_INVALID_PARAMETER; 60 68 #else 61 69 RT_NOREF2(pszPath, cbPath); … … 64 72 } 65 73 66 int DnDPathSanitize(char *pszPath, size_t cbPath) 74 /** 75 * Validates whether a given path matches our set of rules or not. 76 * 77 * @returns VBox status code. 78 * @param pcszPath Path to validate. 79 * @param fMustExist Whether the path to validate also must exist. 80 * @sa shClTransferValidatePath(). 81 */ 82 int DnDPathValidate(const char *pcszPath, bool fMustExist) 67 83 { 68 /** @todo */ 69 RT_NOREF2(pszPath, cbPath); 84 int rc = VINF_SUCCESS; 85 86 if (!strlen(pcszPath)) 87 rc = VERR_INVALID_PARAMETER; 88 89 if ( RT_SUCCESS(rc) 90 && !RTStrIsValidEncoding(pcszPath)) 91 { 92 rc = VERR_INVALID_UTF8_ENCODING; 93 } 94 95 if ( RT_SUCCESS(rc) 96 && RTStrStr(pcszPath, "..")) 97 { 98 rc = VERR_INVALID_PARAMETER; 99 } 100 101 if ( RT_SUCCESS(rc) 102 && fMustExist) 103 { 104 RTFSOBJINFO objInfo; 105 rc = RTPathQueryInfo(pcszPath, &objInfo, RTFSOBJATTRADD_NOTHING); 106 if (RT_SUCCESS(rc)) 107 { 108 if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode)) 109 { 110 if (!RTDirExists(pcszPath)) /* Path must exist. */ 111 rc = VERR_PATH_NOT_FOUND; 112 } 113 else if (RTFS_IS_FILE(objInfo.Attr.fMode)) 114 { 115 if (!RTFileExists(pcszPath)) /* File must exist. */ 116 rc = VERR_FILE_NOT_FOUND; 117 } 118 else /* Everything else (e.g. symbolic links) are not supported. */ 119 rc = VERR_NOT_SUPPORTED; 120 } 121 } 122 123 return rc; 124 } 125 126 /** 127 * Converts a DnD path. 128 * 129 * @returns VBox status code. 130 * @param pszPath Path to convert. 131 * @param cbPath Size (in bytes) of path to convert. 132 * @param fFlags Conversion flags of type DNDPATHCONVERT_FLAGS_. 133 */ 134 int DnDPathConvert(char *pszPath, size_t cbPath, DNDPATHCONVERTFLAGS fFlags) 135 { 136 RT_NOREF(cbPath); 137 AssertReturn(!(fFlags & ~DNDPATHCONVERT_FLAGS_VALID_MASK), VERR_INVALID_FLAGS); 138 139 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) 140 if (fFlags & DNDPATHCONVERT_FLAGS_TO_NATIVE) 141 RTPathChangeToDosSlashes(pszPath, true); 142 else 143 #else 144 RT_NOREF(fFlags); 145 #endif 146 { 147 RTPathChangeToUnixSlashes(pszPath, true /* fForce */); 148 } 149 70 150 return VINF_SUCCESS; 71 151 } -
trunk/src/VBox/GuestHost/DragAndDrop/DnDURIList.cpp
r84998 r85002 385 385 : pszFileName - pszSrcPath; 386 386 char *pszDstPath = &pszSrcPath[cchDstBase]; 387 rc = DnDPath Sanitize(pszDstPath, strlen(pszDstPath));387 rc = DnDPathConvert(pszDstPath, strlen(pszDstPath), DNDPATHCONVERT_FLAGS_NONE); 388 388 if (RT_SUCCESS(rc)) 389 389 { … … 499 499 if (pszFilePath) 500 500 { 501 rc = DnDPath Sanitize(pszFilePath, strlen(pszFilePath));501 rc = DnDPathConvert(pszFilePath, strlen(pszFilePath), DNDPATHCONVERT_FLAGS_NONE); 502 502 if (RT_SUCCESS(rc)) 503 503 { -
trunk/src/VBox/GuestHost/DragAndDrop/DnDURIObject.cpp
r84999 r85002 170 170 { 171 171 AssertReturn(m_strPathAbs.isNotEmpty(), VERR_INVALID_PARAMETER); 172 rc = DnDPath Sanitize(m_strPathAbs.mutableRaw(), m_strPathAbs.capacity());172 rc = DnDPathConvert(m_strPathAbs.mutableRaw(), m_strPathAbs.capacity(), DNDPATHCONVERT_FLAGS_TO_NATIVE); 173 173 if (RT_SUCCESS(rc)) 174 174 { -
trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp
r84998 r85002 816 816 } 817 817 818 rc = DnDPathSanitize(pszPathAbs, sizeof(pszPathAbs));819 if (RT_FAILURE(rc))820 {821 LogFlowFunc(("Warning: Rebasing current file failed with rc=%Rrc\n", rc));822 break;823 }824 825 LogRel2(("DnD: Absolute file path for guest file on the host is now '%s'\n", pszPathAbs));826 827 818 rc = pObj->Init(DnDURIObject::Type_File, pszPathAbs); 828 819 if (RT_SUCCESS(rc))
Note:
See TracChangeset
for help on using the changeset viewer.