Changeset 20020 in vbox for trunk/src/VBox/HostServices/SharedFolders
- Timestamp:
- May 26, 2009 10:06:21 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 47743
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp
r19174 r20020 178 178 } 179 179 180 static int vbsfPathCheck(const char *pUtf8Path, size_t cbPath) 181 { 182 int rc = VINF_SUCCESS; 183 184 /* The pUtf8Path is what the guest sent. Verify that the path is within the root. 185 * Count '..' and other path components and check that we do not go over the root. 186 */ 187 188 size_t i = 0; 189 int cComponents = 0; /* How many normal path components. */ 190 int cParentDirs = 0; /* How many '..' components. */ 191 192 for (;;) 193 { 194 /* Skip leading path delimiters. */ 195 while ( i < cbPath 196 && (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/')) 197 i++; 198 199 if (i >= cbPath) 200 break; 201 202 /* Check if that is a dot component. */ 203 int cDots = 0; 204 while (i < cbPath && pUtf8Path[i] == '.') 205 { 206 cDots++; 207 i++; 208 } 209 210 if ( cDots >= 2 /* Consider all multidots sequences as a 'parent dir'. */ 211 && (i >= cbPath || (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/'))) 212 { 213 cParentDirs++; 214 } 215 else if ( cDots == 1 216 && (i >= cbPath || (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/'))) 217 { 218 /* Single dot, nothing changes. */ 219 } 220 else 221 { 222 /* Skip this component. */ 223 while ( i < cbPath 224 && (pUtf8Path[i] != '\\' && pUtf8Path[i] != '/')) 225 i++; 226 227 cComponents++; 228 } 229 230 Assert(i >= cbPath || (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/')); 231 232 /* Verify counters for every component. */ 233 if (cParentDirs > cComponents) 234 { 235 rc = VERR_INVALID_NAME; 236 break; 237 } 238 } 239 240 return rc; 241 } 242 180 243 static int vbsfBuildFullPath (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, 181 244 uint32_t cbPath, char **ppszFullPath, uint32_t *pcbFullPathRoot, bool fWildCard = false) … … 200 263 char *utf8Root; 201 264 202 rc = RTUtf16ToUtf8 (pwszRoot, &utf8Root); 265 /* Verify that the path is under the root directory. */ 266 rc = vbsfPathCheck((char *)&pPath->String.utf8[0], pPath->u16Length); 267 268 if (RT_SUCCESS (rc)) 269 { 270 rc = RTUtf16ToUtf8 (pwszRoot, &utf8Root); 271 } 272 203 273 if (RT_SUCCESS (rc)) 204 274 { … … 345 415 AssertFailed(); 346 416 #ifdef RT_OS_DARWIN 347 348 417 RTMemFree(pPath); 418 pPath = pPathParameter; 349 419 #endif 350 420 return rc; … … 352 422 353 423 uint32_t l = (uint32_t)strlen (dst); 424 425 /* Verify that the path is under the root directory. */ 426 rc = vbsfPathCheck(dst, l); 427 428 if (RT_FAILURE(rc)) 429 { 430 #ifdef RT_OS_DARWIN 431 RTMemFree(pPath); 432 pPath = pPathParameter; 433 #endif 434 return rc; 435 } 354 436 355 437 cb -= l;
Note:
See TracChangeset
for help on using the changeset viewer.