VirtualBox

Changeset 108849 in vbox


Ignore:
Timestamp:
Apr 4, 2025 11:54:52 AM (6 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168299
Message:

WINNT/Shared Folders/np: NPGetConnection() returns characters for *pBufferSize, not bytes. bugref:10884

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/SharedFolders/np/vboxmrxnp.cpp

    r106061 r108849  
    11/* $Id$ */
    22/** @file
    3  * VirtualBox Windows Guest Shared Folders - Network provider dll
     3 * VirtualBox Windows Guest Shared Folders - Network provider DLL (ring-3).
     4 *
     5 * Communicates with the ring-0 VBoxSF.sys via IOCtls.
    46 */
    57
     
    484486{
    485487    DWORD dwStatus = WN_NOT_CONNECTED;
    486 
    487488    WCHAR RemoteName[128];
    488     ULONG cbOut = 0;
    489 
    490     Log(("VBOXNP: NPGetConnection: pLocalName = %ls\n",
    491          pLocalName));
     489
     490    Log(("VBOXNP: NPGetConnection: pLocalName = %ls, *pBufferSize=%d\n", pLocalName, *pBufferSize));
    492491
    493492    if (pLocalName && pLocalName[0] != 0)
     
    495494        if (pLocalName[1] == L':')
    496495        {
     496            ULONG cbOut = 0;
    497497            WCHAR LocalName[3];
    498498
     
    515515                dwStatus = WN_NOT_CONNECTED;
    516516            }
    517             else
    518             {
     517            else if (cbOut)
     518            {
     519                Assert(cbOut % sizeof(WCHAR) == 0); /* Paranoia. */
    519520                RemoteName[cbOut / sizeof(WCHAR)] = 0;
    520 
    521                 if (cbOut == 0)
    522                 {
    523                     dwStatus = WN_NO_NETWORK;
    524                 }
    525             }
     521            }
     522            else /* Buggy VBoxSF.sys code. */
     523                AssertFailedStmt(dwStatus = WN_NO_NETWORK);
    526524        }
    527525    }
     
    529527    if (dwStatus == WN_SUCCESS)
    530528    {
    531         ULONG cbRemoteName = (lstrlen(RemoteName) + 1) * sizeof (WCHAR); /* Including the trailing 0. */
    532 
    533         Log(("VBOXNP: NPGetConnection: RemoteName: %ls, cb %d\n",
     529        ULONG const cbRemoteName = (  1 /* Including the leading '\' */
     530                                    + lstrlen(RemoteName)
     531                                    + 1 /* Include terminatior */)
     532                                 * sizeof (WCHAR);
     533
     534        Log(("VBOXNP: NPGetConnection: RemoteName: %ls -> cbRemoteName %d\n",
    534535             RemoteName, cbRemoteName));
    535536
    536         DWORD len = sizeof(WCHAR) + cbRemoteName; /* Including the leading '\'. */
    537 
    538         if (*pBufferSize >= len)
     537        /* Note: *pBufferSize is characters, not bytes! */
     538        if (*pBufferSize * sizeof(WCHAR) >= cbRemoteName)
    539539        {
    540540            pRemoteName[0] = L'\\';
    541             CopyMemory(&pRemoteName[1], RemoteName, cbRemoteName);
     541            CopyMemory(&pRemoteName[1], RemoteName, cbRemoteName - sizeof(pRemoteName[0]) /* Skip leading '\' */);
    542542
    543543            Log(("VBOXNP: NPGetConnection: returning pRemoteName: %ls\n",
     
    549549            {
    550550                /* Log only real errors. Do not log a 0 bytes try. */
    551                 Log(("VBOXNP: NPGetConnection: Buffer overflow: *pBufferSize = %d, len = %d\n",
    552                      *pBufferSize, len));
     551                Log(("VBOXNP: NPGetConnection: Buffer overflow: *pBufferSize = %d < cbRemoteName = %d\n",
     552                     *pBufferSize, cbRemoteName));
    553553            }
    554554
     
    556556        }
    557557
    558         *pBufferSize = len;
    559     }
    560 
    561     if ((dwStatus != WN_SUCCESS) &&
    562         (dwStatus != WN_MORE_DATA))
    563     {
    564         Log(("VBOXNP: NPGetConnection: Returned error 0x%08X\n",
    565              dwStatus));
    566     }
     558        Assert(cbRemoteName % sizeof(WCHAR) == 0);
     559        *pBufferSize = cbRemoteName / sizeof(WCHAR); /* Length in characters, not bytes! */
     560    }
     561
     562    if (   (dwStatus != WN_SUCCESS)
     563        && (dwStatus != WN_MORE_DATA))
     564        Log(("VBOXNP: NPGetConnection: Returned error 0x%08X\n", dwStatus));
    567565
    568566    return dwStatus;
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