VirtualBox

Changeset 69536 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 31, 2017 9:18:24 AM (7 years ago)
Author:
vboxsync
Message:

IPRT: Go seriously paranoid on written byte counts returned by WriteFile calls.

Location:
trunk/src/VBox/Runtime/r3/win
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r69111 r69536  
    496496    if (cbToWrite <= 0)
    497497        return VINF_SUCCESS;
    498     ULONG cbToWriteAdj = (ULONG)cbToWrite;
     498    ULONG const cbToWriteAdj = (ULONG)cbToWrite;
    499499    AssertReturn(cbToWriteAdj == cbToWrite, VERR_NUMBER_TOO_BIG);
    500500
     
    504504        if (pcbWritten)
    505505            /* Caller can handle partial writes. */
    506             *pcbWritten = cbWritten;
     506            *pcbWritten = RT_MIN(cbWritten, cbToWriteAdj); /* paranoia^3 */
    507507        else
    508508        {
    509509            /* Caller expects everything to be written. */
    510             while (cbToWriteAdj > cbWritten)
     510            while (cbWritten < cbToWriteAdj)
    511511            {
    512512                ULONG cbWrittenPart = 0;
     
    543543
    544544        cbWritten = 0;
    545         while (cbToWriteAdj > cbWritten)
     545        while (cbWritten < cbToWriteAdj)
    546546        {
    547547            ULONG cbToWrite     = RT_MIN(cbChunk, cbToWriteAdj - cbWritten);
     
    570570            if (pcbWritten)
    571571            {
    572                 *pcbWritten = cbWritten;
     572                *pcbWritten = RT_MIN(cbWritten, cbToWriteAdj); /* paranoia^3 */
    573573                break;
    574574            }
  • trunk/src/VBox/Runtime/r3/win/localipc-win.cpp

    r69111 r69536  
    13921392                    RTCritSectLeave(&pThis->CritSect);
    13931393
    1394                     fRc = WriteFile(pThis->hNmPipe, pvBuf,
    1395                                     cbToWrite <= ~(DWORD)0 ? (DWORD)cbToWrite : ~(DWORD)0,
    1396                                     &cbWritten, &pThis->Write.OverlappedIO);
     1394                    DWORD const cbToWriteInThisIteration = cbToWrite <= ~(DWORD)0 ? (DWORD)cbToWrite : ~(DWORD)0;
     1395                    fRc = WriteFile(pThis->hNmPipe, pvBuf, cbToWriteInThisIteration, &cbWritten, &pThis->Write.OverlappedIO);
    13971396                    if (fRc)
    13981397                        rc = VINF_SUCCESS;
     
    14231422                    }
    14241423
     1424                    if (cbWritten > cbToWriteInThisIteration) /* paranoia^3 */
     1425                        cbWritten = cbToWriteInThisIteration;
     1426
    14251427                    RTCritSectEnter(&pThis->CritSect);
    14261428                    if (RT_FAILURE(rc))
  • trunk/src/VBox/Runtime/r3/win/pipe-win.cpp

    r69111 r69536  
    797797                                  &cbWritten, &pThis->Overlapped))
    798798                    {
    799                         *pcbWritten = cbWritten;
     799                        *pcbWritten = RT_MIN(cbWritten, cbToWrite); /* paranoia^3 */
    800800                        rc = VINF_SUCCESS;
    801801                    }
     
    879879
    880880                    DWORD cbWritten = 0;
    881                     if (WriteFile(pThis->hPipe, pvBuf,
    882                                   cbToWrite <= ~(DWORD)0 ? (DWORD)cbToWrite : ~(DWORD)0,
    883                                   &cbWritten, &pThis->Overlapped))
     881                    DWORD const cbToWriteInThisIteration = cbToWrite <= ~(DWORD)0 ? (DWORD)cbToWrite : ~(DWORD)0;
     882                    if (WriteFile(pThis->hPipe, pvBuf, cbToWriteInThisIteration, &cbWritten, &pThis->Overlapped))
    884883                        rc = VINF_SUCCESS;
    885884                    else if (GetLastError() == ERROR_IO_PENDING)
     
    902901
    903902                    /* advance */
     903                    if (cbWritten > cbToWriteInThisIteration) /* paranoia^3 */
     904                        cbWritten = cbToWriteInThisIteration;
    904905                    pvBuf           = (char const *)pvBuf + cbWritten;
    905906                    cbTotalWritten += cbWritten;
Note: See TracChangeset for help on using the changeset viewer.

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