VirtualBox

Changeset 100620 in vbox


Ignore:
Timestamp:
Jul 18, 2023 9:20:07 AM (20 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158451
Message:

Shared Clipboard: Make sure to encode HTTP URLs, to also support files with special characters. bugref:9437

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers-http.cpp

    r100367 r100620  
    5353#include <iprt/string.h>
    5454#include <iprt/thread.h>
     55#include <iprt/uri.h>
    5556#include <iprt/uuid.h>
    5657#include <iprt/vfs.h>
     
    881882                /* Create the virtual HTTP path for the transfer.
    882883                 * Every transfer has a dedicated HTTP path (but live in the same URL namespace). */
     884                char *pszPath;
    883885#ifdef VBOX_SHCL_DEBUG_HTTPSERVER
    884886# ifdef DEBUG_andy /** Too lazy to specify a different transfer ID for debugging. */
    885                 ssize_t cch = RTStrPrintf2(pSrvTx->szPathVirtual, sizeof(pSrvTx->szPathVirtual), "/transfer");
     887                ssize_t cch = RTStrAPrintf(&pszPath, "//transfer");
    886888# else
    887                 ssize_t cch = RTStrPrintf2(pSrvTx->szPathVirtual, sizeof(pSrvTx->szPathVirtual), "/transfer%RU16",
    888                                            pTransfer->State.uID);
     889                ssize_t cch = RTStrPrintf2(&pszPath, "//transfer%RU16", pTransfer->State.uID);
    889890# endif
    890 #else
    891                 ssize_t cch = RTStrPrintf2(pSrvTx->szPathVirtual, sizeof(pSrvTx->szPathVirtual), "/%s/%s/%s",
    892                                            SHCL_HTTPT_URL_NAMESPACE, szUuid, pEntry->pszName);
     891#else /* Release mode */
     892                ssize_t cch = RTStrPrintf2(&pszPath, "//%s/%s/%s", SHCL_HTTPT_URL_NAMESPACE, szUuid, pEntry->pszName);
    893893#endif
    894                 AssertReturn(cch, VERR_BUFFER_OVERFLOW);
     894                AssertReturn(cch, VERR_NO_MEMORY);
     895
     896                const char   szScheme[] = "http"; /** @todo For now we only support HTTP. */
     897                const size_t cchScheme  = strlen(szScheme) + 3 /* "://" */;
     898
     899                char *pszURI = RTUriCreate(szScheme, NULL /* pszAuthority */, pszPath, NULL /* pszQuery */, NULL /* pszFragment */);
     900                if (pszURI)
     901                {
     902                    if (strlen(pszURI) >= cchScheme)
     903                    {
     904                        /* For the virtual path we only keep everything after the full scheme (e.g. "http://").
     905                         * The virtual path always has to start with a "/". */
     906                        if (RTStrPrintf2(pSrvTx->szPathVirtual, sizeof(pSrvTx->szPathVirtual), "/%s", pszURI + cchScheme) <= 0)
     907                            rc = VERR_BUFFER_OVERFLOW;
     908                    }
     909                    else
     910                        rc = VERR_INVALID_PARAMETER;
     911
     912                    RTStrFree(pszURI);
     913                    pszURI = NULL;
     914                }
     915                else
     916                    rc = VERR_NO_MEMORY;
     917
     918                RTStrFree(pszPath);
     919                pszPath = NULL;
     920
     921                AssertRCReturn(rc, rc);
    895922
    896923                pSrvTx->pTransfer = pTransfer;
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