VirtualBox

Ignore:
Timestamp:
Dec 24, 2021 12:12:04 AM (3 years ago)
Author:
vboxsync
Message:

os2/VBoxSF: Fixed off by one check in vboxSfOs2MakeEmptyEaListEx. Fixed problem with missing FEAList length when called from vboxSfOs2ReadDirEntries. ticketref:19453

Location:
trunk/src/VBox/Additions/os2/VBoxSF
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/os2/VBoxSF/VBoxSF.cpp

    r79112 r93071  
    19641964 * @param   pEaOp           Kernel copy of the EA request with flattened pointers.
    19651965 * @param   uLevel          The info level being queried.
     1966 * @param   cbFullEasLeft   The size of the full EA buffer, ~(ULONG)0 if it
     1967 *                          should be read in from pEaOp->fpFEAList->cbList.
    19661968 * @param   pcbWritten      Where to return the length of the resulting list.  Optional.
    19671969 * @param   poffError       User buffer address of EAOP.oError for reporting GEALIST issues.
    19681970 */
    1969 APIRET vboxSfOs2MakeEmptyEaListEx(PEAOP pEaOp, ULONG uLevel, uint32_t *pcbWritten, ULONG *poffError)
     1971APIRET vboxSfOs2MakeEmptyEaListEx(PEAOP pEaOp, ULONG uLevel, ULONG cbFullEasLeft, uint32_t *pcbWritten, ULONG *poffError)
    19701972{
    19711973    ULONG  cbDstList;
     
    19901992        ULONG cbGetEasLeft = 0;
    19911993        rc = KernCopyIn(&cbGetEasLeft, &pEaOp->fpGEAList->cbList, sizeof(pEaOp->fpGEAList->cbList));
    1992         ULONG cbFullEasLeft = 0;
    1993         if (rc == NO_ERROR)
     1994        if (rc == NO_ERROR && cbFullEasLeft == ~(ULONG)0)
    19941995            rc = KernCopyIn(&cbFullEasLeft, &pEaOp->fpFEAList->cbList, sizeof(cbFullEasLeft));
    19951996        if (   rc == NO_ERROR
     
    20132014                 * pbSrc: GEA: BYTE cbName; char szName[];
    20142015                 */
    2015                 /* Get name length. */
    2016                 uint8_t cbName = 0;
    2017                 rc = KernCopyIn(&cbName, pbSrc, sizeof(cbName));
    2018                 Log3(("vboxSfOs2MakeEmptyEaList: cbName=%#x rc=%u\n", cbName, rc));
     2016                /* Get name length (we call it cchName instead of cbName since
     2017                   it does not include the zero terminator). */
     2018                uint8_t cchName = 0;
     2019                rc = KernCopyIn(&cchName, pbSrc, sizeof(cchName));
     2020                Log3(("vboxSfOs2MakeEmptyEaList: cchName=%#x rc=%u\n", cchName, rc));
    20192021                if (rc != NO_ERROR)
    20202022                    break;
    20212023                pbSrc++;
    20222024                cbGetEasLeft--;
    2023                 if (cbName + 1U > cbGetEasLeft)
     2025                if (cchName + 1U > cbGetEasLeft)
    20242026                {
    20252027                    cbDstList = pbSrc - 1 - (uint8_t *)pEaOp->fpGEAList;
     
    20322034
    20332035                /* Copy in name. */
    2034                 rc = KernCopyIn(pszNameBuf, pbSrc, cbName + 1);
     2036                rc = KernCopyIn(pszNameBuf, pbSrc, cchName + 1);
    20352037                if (rc != NO_ERROR)
    20362038                    break;
    2037                 Log3(("vboxSfOs2MakeEmptyEaList: szName: %.*Rhxs\n", cbName + 1, pszNameBuf));
    2038                 if ((char *)memchr(pszNameBuf, '\0', cbName) != &pszNameBuf[cbName])
     2039                Log3(("vboxSfOs2MakeEmptyEaList: szName: %.*Rhxs\n", cchName + 1, pszNameBuf));
     2040                if ((char *)memchr(pszNameBuf, '\0', cchName + 1) != &pszNameBuf[cchName])
    20392041                {
    20402042                    cbDstList = pbSrc - 1 - (uint8_t *)pEaOp->fpGEAList;
     
    20472049
    20482050                /* Skip input. */
    2049                 cbGetEasLeft -= cbName + 1;
    2050                 pbSrc        += cbName + 1;
     2051                cbGetEasLeft -= cchName + 1;
     2052                pbSrc        += cchName + 1;
    20512053
    20522054                /*
     
    20542056                 * Note! We should technically skip duplicates here, but who cares...
    20552057                 */
    2056                 if (cbName > 0)
     2058                if (cchName > 0)
    20572059                {
    20582060                    FEA Result;
    2059                     if (sizeof(Result) + cbName + 1 > cbFullEasLeft)
     2061                    if (sizeof(Result) + cchName + 1 <= cbFullEasLeft)
     2062                        cbFullEasLeft -= sizeof(Result) + cchName + 1;
     2063                    else
    20602064                    {
    2061                         Log(("vboxSfOs2MakeEmptyEaList: ERROR_BUFFER_OVERFLOW (%#x vs %#x)\n", sizeof(Result) + cbName + 1, cbFullEasLeft));
     2065                        Log(("vboxSfOs2MakeEmptyEaList: ERROR_BUFFER_OVERFLOW (%#x vs %#x)\n", sizeof(Result) + cchName + 1, cbFullEasLeft));
    20622066                        rc = ERROR_BUFFER_OVERFLOW;
    20632067                        break;
    20642068                    }
    2065                     cbFullEasLeft -= sizeof(Result) + cbName + 1;
    20662069
    20672070                    Result.fEA     = 0;
    2068                     Result.cbName  = cbName;
     2071                    Result.cbName  = cchName;
    20692072                    Result.cbValue = 0;
    20702073                    rc = KernCopyOut(pbDst, &Result, sizeof(Result));
     
    20732076                    pbDst += sizeof(Result);
    20742077
    2075                     rc = KernCopyOut(pbDst, pszNameBuf, cbName + 1);
     2078                    rc = KernCopyOut(pbDst, pszNameBuf, cchName + 1);
    20762079                    if (rc != NO_ERROR)
    20772080                        break;
    2078                     pbDst += cbName + 1;
     2081                    pbDst += cchName + 1;
    20792082                }
    20802083            } /* (while more GEAs) */
     
    21352138        Log2(("vboxSfOs2MakeEmptyEaList: #0b: %p %p\n", EaOp.fpGEAList, EaOp.fpFEAList));
    21362139
    2137         rc = vboxSfOs2MakeEmptyEaListEx(&EaOp, uLevel, NULL, &pEaOp->oError);
     2140        rc = vboxSfOs2MakeEmptyEaListEx(&EaOp, uLevel, ~(ULONG)0, NULL, &pEaOp->oError);
    21382141    }
    21392142    return rc;
  • trunk/src/VBox/Additions/os2/VBoxSF/VBoxSFFind.cpp

    r84484 r93071  
    344344                        pbDst   = pbToCopy;
    345345
     346                        /* Output empty EA list.  We don't try anticipate filename output length here,
     347                           instead we'll just handle that when we come to it below. */
     348                        /** @todo If this overflows, JFS will return ERROR_EAS_DIDNT_FIT and just the
     349                         * EA size here (i.e. as if FI_LVL_STANDARD_EASIZE or _64 was requested).
     350                         * I think, however, that ERROR_EAS_DIDNT_FIT should only be considered if
     351                         * this is the first entry we're returning and we'll have to stop after it. */
    346352                        uint32_t cbWritten = 0;
    347353                        EaOp.fpFEAList = (PFEALIST)pbData;
    348                         rc = vboxSfOs2MakeEmptyEaListEx(&EaOp, uLevel, &cbWritten, &pEaOpUser->oError);
     354                        rc = vboxSfOs2MakeEmptyEaListEx(&EaOp, uLevel, cbData, &cbWritten, &pEaOpUser->oError);
    349355                        if (rc == NO_ERROR)
    350356                        {
  • trunk/src/VBox/Additions/os2/VBoxSF/VBoxSFInternal.h

    r84509 r93071  
    249249APIRET      vboxSfOs2CheckEaOpForCreation(EAOP const *pEaOp);
    250250APIRET      vboxSfOs2MakeEmptyEaList(PEAOP pEaOp, ULONG uLevel);
    251 APIRET      vboxSfOs2MakeEmptyEaListEx(PEAOP pEaOp, ULONG uLevel, uint32_t *pcbWritten, ULONG *poffError);
     251APIRET      vboxSfOs2MakeEmptyEaListEx(PEAOP pEaOp, ULONG uLevel, ULONG cbFullEasLeft, uint32_t *pcbWritten, ULONG *poffError);
    252252
    253253DECLASM(PVBOXSFVP)  Fsh32GetVolParams(USHORT hVbp, PVPFSI *ppVpFsi /*optional*/);
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