VirtualBox

Ignore:
Timestamp:
Oct 22, 2019 7:36:15 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134181
Message:

Shared Clipboard/Transfers: Various bugfixes.

Location:
trunk/src/VBox/GuestHost/SharedClipboard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardDataObjectImpl-win.cpp

    r81438 r81460  
    265265                    {
    266266                        SHCLLISTENTRY entryList;
    267                         rc = ShClTransferListRead(pTransfer, hList, &entryList);
     267                        rc = ShClTransferListEntryInit(&entryList);
    268268                        if (RT_SUCCESS(rc))
    269269                        {
    270                             PSHCLFSOBJINFO pFsObjInfo = (PSHCLFSOBJINFO)entryList.pvInfo;
    271                             Assert(entryList.cbInfo == sizeof(SHCLFSOBJINFO));
    272 
    273                             Utf8Str strPath = strDir + Utf8Str("\\") + Utf8Str(entryList.pszName);
    274 
    275                             LogFlowFunc(("\t%s (%RU64 bytes) -> %s\n",
    276                                          entryList.pszName, pFsObjInfo->cbObject, strPath.c_str()));
    277 
    278                             if (RTFS_IS_DIRECTORY(pFsObjInfo->Attr.fMode))
     270                            rc = ShClTransferListRead(pTransfer, hList, &entryList);
     271                            if (RT_SUCCESS(rc))
    279272                            {
    280                                 /* Note: Directories are *not* required to be part of m_lstEntries, as we only
    281                                  *       count files to transfer there. */
    282 
    283                                 rc = readDir(pTransfer, strPath.c_str());
     273                                if (ShClTransferListEntryIsValid(&entryList))
     274                                {
     275                                    PSHCLFSOBJINFO pFsObjInfo = (PSHCLFSOBJINFO)entryList.pvInfo;
     276                                    Assert(entryList.cbInfo == sizeof(SHCLFSOBJINFO));
     277
     278                                    Utf8Str strPath = strDir + Utf8Str("\\") + Utf8Str(entryList.pszName);
     279
     280                                    LogFlowFunc(("\t%s (%RU64 bytes) -> %s\n",
     281                                                 entryList.pszName, pFsObjInfo->cbObject, strPath.c_str()));
     282
     283                                    if (RTFS_IS_DIRECTORY(pFsObjInfo->Attr.fMode))
     284                                    {
     285                                        FSOBJENTRY objEntry = { strPath.c_str(), *pFsObjInfo };
     286
     287                                        m_lstEntries.push_back(objEntry); /** @todo Can this throw? */
     288
     289                                        rc = readDir(pTransfer, strPath.c_str());
     290                                    }
     291                                    else if (RTFS_IS_FILE(pFsObjInfo->Attr.fMode))
     292                                    {
     293                                        FSOBJENTRY objEntry = { strPath.c_str(), *pFsObjInfo };
     294
     295                                        m_lstEntries.push_back(objEntry); /** @todo Can this throw? */
     296                                    }
     297                                    else
     298                                        rc = VERR_NOT_SUPPORTED;
     299
     300                                    /** @todo Handle symlinks. */
     301                                }
     302                                else
     303                                    rc = VERR_INVALID_PARAMETER;
    284304                            }
    285                             else if (RTFS_IS_FILE(pFsObjInfo->Attr.fMode))
    286                             {
    287                                 FSOBJENTRY objEntry = { strPath.c_str(), *pFsObjInfo };
    288 
    289                                 m_lstEntries.push_back(objEntry); /** @todo Can this throw? */
    290                             }
    291 
    292                             /** @todo Handle symlinks. */
     305
     306                            ShClTransferListEntryDestroy(&entryList);
    293307                        }
    294308
     
    359373                if (RTFS_IS_DIRECTORY(pFsObjInfo->Attr.fMode))
    360374                {
    361                     /* Note: Directories are *not* required to be part of m_lstEntries, as we only
    362                      *       count files to transfer there. */
     375                    FSOBJENTRY objEntry = { pRootEntry->pszName, *pFsObjInfo };
     376
     377                    pThis->m_lstEntries.push_back(objEntry); /** @todo Can this throw? */
    363378
    364379                    rc = pThis->readDir(pTransfer, pRootEntry->pszName);
     
    370385                    pThis->m_lstEntries.push_back(objEntry); /** @todo Can this throw? */
    371386                }
     387                else
     388                    rc = VERR_NOT_SUPPORTED;
    372389
    373390                if (ASMAtomicReadBool(&pTransfer->Thread.fStop))
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers.cpp

    r81440 r81460  
    541541int ShClTransferListEntryInit(PSHCLLISTENTRY pListEntry)
    542542{
     543    AssertPtrReturn(pListEntry, VERR_INVALID_POINTER);
     544
    543545    RT_BZERO(pListEntry, sizeof(SHCLLISTENTRY));
    544546
     
    588590
    589591/**
    590  * Returns whether a given clipboard data chunk is valid or not.
     592 * Returns whether a given clipboard list entry is valid or not.
    591593 *
    592594 * @returns \c true if valid, \c false if not.
    593  * @param   pListEntry          Clipboard data chunk to validate.
     595 * @param   pListEntry          Clipboard list entry to validate.
    594596 */
    595597bool ShClTransferListEntryIsValid(PSHCLLISTENTRY pListEntry)
    596598{
    597     RT_NOREF(pListEntry);
    598 
    599     /** @todo Verify checksum. */
    600 
    601     return true; /** @todo Implement this. */
     599    AssertPtrReturn(pListEntry, false);
     600
     601    if (   !pListEntry->pszName
     602        || !pListEntry->cbName
     603        || strlen(pListEntry->pszName) == 0
     604        || strlen(pListEntry->pszName) > pListEntry->cbName /* Includes zero termination */ - 1)
     605    {
     606        return false;
     607    }
     608
     609    if (pListEntry->cbInfo) /* cbInfo / pvInfo is optional. */
     610    {
     611        if (!pListEntry->pvInfo)
     612            return false;
     613    }
     614
     615    return true;
    602616}
    603617
     
    12051219    pTransfer->pszPathRootAbs    = NULL;
    12061220
    1207     pTransfer->uListHandleNext   = 1;
    1208     pTransfer->uObjHandleNext    = 1;
    1209 
    12101221    pTransfer->uTimeoutMs     = 30 * 1000; /* 30s timeout by default. */
    12111222    pTransfer->cbMaxChunkSize = _64K; /** @todo Make this configurable. */
     
    12601271        return rc;
    12611272
    1262     RTStrFree(pTransfer->pszPathRootAbs);
     1273    ShClTransferReset(pTransfer);
    12631274
    12641275    ShClEventSourceDestroy(&pTransfer->Events);
    1265 
    1266     PSHCLLISTHANDLEINFO pItList, pItListNext;
    1267     RTListForEachSafe(&pTransfer->lstList, pItList, pItListNext, SHCLLISTHANDLEINFO, Node)
    1268     {
    1269         ShClTransferListHandleInfoDestroy(pItList);
    1270 
    1271         RTListNodeRemove(&pItList->Node);
    1272 
    1273         RTMemFree(pItList);
    1274     }
    1275 
    1276     PSHCLOBJHANDLEINFO pItObj, pItObjNext;
    1277     RTListForEachSafe(&pTransfer->lstObj, pItObj, pItObjNext, SHCLOBJHANDLEINFO, Node)
    1278     {
    1279         ShClTransferObjHandleInfoDestroy(pItObj);
    1280 
    1281         RTListNodeRemove(&pItObj->Node);
    1282 
    1283         RTMemFree(pItObj);
    1284     }
    12851276
    12861277    LogFlowFuncLeave();
     
    12891280
    12901281/**
    1291  * Initializes a shared Clipboard transfer object.
     1282 * Initializes a Shared Clipboard transfer object.
    12921283 *
    12931284 * @returns VBox status code.
     
    13121303        pTransfer->State.enmStatus = SHCLTRANSFERSTATUS_INITIALIZED; /* Now we're ready to run. */
    13131304
     1305        pTransfer->cListHandles    = 0;
    13141306        pTransfer->cMaxListHandles = _4K; /** @todo Make this dynamic. */
     1307        pTransfer->uListHandleNext = 1;
     1308
     1309        pTransfer->cObjHandles     = 0;
    13151310        pTransfer->cMaxObjHandles  = _4K; /** @todo Ditto. */
     1311        pTransfer->uObjHandleNext  = 1;
    13161312
    13171313        if (pTransfer->Callbacks.pfnTransferInitialize)
     
    19671963                                if (RT_SUCCESS(rc))
    19681964                                {
     1965                                    pEntry->cbName = (uint32_t)strlen(pEntry->pszName) + 1; /* Include termination. */
     1966
    19691967                                    AssertPtr(pEntry->pvInfo);
    19701968                                    Assert   (pEntry->cbInfo == sizeof(SHCLFSOBJINFO));
    19711969
    19721970                                    ShClFsObjFromIPRT(PSHCLFSOBJINFO(pEntry->pvInfo), &pDirEntry->Info);
     1971
     1972                                    LogFlowFunc(("Entry pszName=%s, pvInfo=%p, cbInfo=%RU32\n",
     1973                                                 pEntry->pszName, pEntry->pvInfo, pEntry->cbInfo));
    19731974                                }
    19741975                            }
     
    21172118
    21182119/**
    2119  * Clears (resets) the root list of a shared Clipboard transfer.
     2120 * Clears (resets) the root list of a Shared Clipboard transfer.
    21202121 *
    21212122 * @param   pTransfer           Transfer to clear transfer root list for.
     
    21462147
    21472148/**
    2148  * Resets a shared Clipboard transfer.
     2149 * Resets a Shared Clipboard transfer.
    21492150 *
    21502151 * @param   pTransfer           Clipboard transfer to reset.
     
    21572158
    21582159    shClTransferListRootsClear(pTransfer);
     2160
     2161    PSHCLLISTHANDLEINFO pItList, pItListNext;
     2162    RTListForEachSafe(&pTransfer->lstList, pItList, pItListNext, SHCLLISTHANDLEINFO, Node)
     2163    {
     2164        ShClTransferListHandleInfoDestroy(pItList);
     2165
     2166        RTListNodeRemove(&pItList->Node);
     2167
     2168        RTMemFree(pItList);
     2169    }
     2170
     2171    PSHCLOBJHANDLEINFO pItObj, pItObjNext;
     2172    RTListForEachSafe(&pTransfer->lstObj, pItObj, pItObjNext, SHCLOBJHANDLEINFO, Node)
     2173    {
     2174        ShClTransferObjHandleInfoDestroy(pItObj);
     2175
     2176        RTListNodeRemove(&pItObj->Node);
     2177
     2178        RTMemFree(pItObj);
     2179    }
    21592180}
    21602181
     
    22702291
    22712292/**
    2272  * Returns the root entries of a shared Clipboard transfer.
     2293 * Returns the root entries of a Shared Clipboard transfer.
    22732294 *
    22742295 * @returns VBox status code.
     
    26962717
    26972718/**
    2698  * Destroys a shared Clipboard transfer context struct.
     2719 * Destroys a Shared Clipboard transfer context struct.
    26992720 *
    27002721 * @param   pTransferCtx                Transfer context to destroy.
     
    27252746
    27262747/**
    2727  * Resets a shared Clipboard transfer.
     2748 * Resets a Shared Clipboard transfer.
    27282749 *
    27292750 * @param   pTransferCtx                Transfer context to reset.
     
    27962817
    27972818/**
    2798  * Registers a shared Clipboard transfer with a transfer context, i.e. allocates a transfer ID.
     2819 * Registers a Shared Clipboard transfer with a transfer context, i.e. allocates a transfer ID.
    27992820 *
    28002821 * @return  VBox status code.
     
    28492870
    28502871/**
    2851  * Registers a shared Clipboard transfer with a transfer contextby specifying an ID for the transfer.
     2872 * Registers a Shared Clipboard transfer with a transfer contextby specifying an ID for the transfer.
    28522873 *
    28532874 * @return  VBox status code.
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