VirtualBox

Changeset 85002 in vbox


Ignore:
Timestamp:
Jun 30, 2020 9:34:16 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
138900
Message:

DnD: More work on path conversion / validation.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/DragAndDrop.h

    r84998 r85002  
    9595bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax);
    9696
     97int DnDPathValidate(const char *pcszPath, bool fMustExist);
     98
     99/** DnD path conversion flags. */
     100typedef 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
     111int DnDPathConvert(char *pszPath, size_t cbPath, DNDPATHCONVERTFLAGS fFlags);
    97112int DnDPathSanitizeFilename(char *pszPath, size_t cbPath);
    98 int DnDPathSanitize(char *pszPath, size_t cbPath);
    99113
    100114/** DnDURIObject flags. */
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDPath.cpp

    r82968 r85002  
    2323#include <VBox/GuestHost/DragAndDrop.h>
    2424
     25#include <iprt/dir.h>
    2526#include <iprt/err.h>
     27#include <iprt/file.h>
    2628#include <iprt/path.h>
    2729#include <iprt/string.h>
     
    5557        '\0'
    5658    };
    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;
    6068#else
    6169    RT_NOREF2(pszPath, cbPath);
     
    6472}
    6573
    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 */
     82int DnDPathValidate(const char *pcszPath, bool fMustExist)
    6783{
    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 */
     134int 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
    70150    return VINF_SUCCESS;
    71151}
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDURIList.cpp

    r84998 r85002  
    385385                                  : pszFileName - pszSrcPath;
    386386                char *pszDstPath = &pszSrcPath[cchDstBase];
    387                 rc = DnDPathSanitize(pszDstPath, strlen(pszDstPath));
     387                rc = DnDPathConvert(pszDstPath, strlen(pszDstPath), DNDPATHCONVERT_FLAGS_NONE);
    388388                if (RT_SUCCESS(rc))
    389389                {
     
    499499        if (pszFilePath)
    500500        {
    501             rc = DnDPathSanitize(pszFilePath, strlen(pszFilePath));
     501            rc = DnDPathConvert(pszFilePath, strlen(pszFilePath), DNDPATHCONVERT_FLAGS_NONE);
    502502            if (RT_SUCCESS(rc))
    503503            {
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDURIObject.cpp

    r84999 r85002  
    170170    {
    171171        AssertReturn(m_strPathAbs.isNotEmpty(), VERR_INVALID_PARAMETER);
    172         rc = DnDPathSanitize(m_strPathAbs.mutableRaw(), m_strPathAbs.capacity());
     172        rc = DnDPathConvert(m_strPathAbs.mutableRaw(), m_strPathAbs.capacity(), DNDPATHCONVERT_FLAGS_TO_NATIVE);
    173173        if (RT_SUCCESS(rc))
    174174        {
  • trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp

    r84998 r85002  
    816816            }
    817817
    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 
    827818            rc = pObj->Init(DnDURIObject::Type_File, pszPathAbs);
    828819            if (RT_SUCCESS(rc))
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette