Changeset 3914 for branches


Ignore:
Timestamp:
Oct 24, 2014, 4:01:38 PM (11 years ago)
Author:
bird
Message:

trunk,0.6: Fixed buffer overflow in fsResolveUnix that would trigger if the input path was too long.

Location:
branches/libc-0.6/src/emx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/include/InnoTekLIBC/backend.h

    r3859 r3914  
    189189/** Get the native path instead, no unix root translations. */
    190190#define __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE      0x10
     191/** Direct buffer mode for testing purposes.  */
     192#define __LIBC_BACKFS_FLAGS_RESOLVE_DIRECT_BUF  0x8000
    191193/** @} */
    192194
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsPathResolve.c

    r3771 r3914  
    6565     */
    6666    int             fInUnixTree = 0;
    67     char            szNativePath[PATH_MAX];
    6867    unsigned int    fBackFsFlags = fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_FULL_MAYBE
    6968                                 ? BACKFS_FLAGS_RESOLVE_DIR_MAYBE | BACKFS_FLAGS_RESOLVE_FULL_MAYBE
    7069                                 : BACKFS_FLAGS_RESOLVE_DIR_MAYBE | BACKFS_FLAGS_RESOLVE_FULL;
    71     szNativePath[0] = szNativePath[1] = szNativePath[2] = szNativePath[3] = '\0';
    72     rc = __libc_back_fsResolve(pszPath, fBackFsFlags, szNativePath, &fInUnixTree);
     70    if (!(fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_DIRECT_BUF))
     71    {
     72        char        szNativePath[PATH_MAX];
     73        szNativePath[0] = szNativePath[1] = szNativePath[2] = szNativePath[3] = '\0';
     74        rc = __libc_back_fsResolve(pszPath, fBackFsFlags, szNativePath, &fInUnixTree);
    7375
    74     /*
    75      * Copy the (half) result back to the caller.
    76      */
    77     char *pszSrc = &szNativePath[0];
    78     if (   !(fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE)
    79         && fInUnixTree
    80         && *pszSrc)
     76        /*
     77         * Copy the (half) result back to the caller.
     78         */
     79        char *pszSrc = &szNativePath[0];
     80        if (   !(fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE)
     81            && fInUnixTree
     82            && *pszSrc)
     83        {
     84            pszSrc += __libc_gcchUnixRoot;
     85            LIBC_ASSERTM(*pszSrc == '/', "bogus fInUnixTree flag! pszSrc='%s' whole thing is '%s'\n", pszSrc, szNativePath);
     86        }
     87        __libc_back_fsMutexRelease();
     88
     89        int cch = strlen(pszSrc) + 1;
     90        if (cch < cchBuf)
     91            memcpy(pszBuf, pszSrc, cchBuf);
     92        else if (!rc)
     93            rc = -ERANGE;
     94    }
     95    else
    8196    {
    82         pszSrc += __libc_gcchUnixRoot;
    83         LIBC_ASSERTM(*pszSrc == '/', "bogus fInUnixTree flag! pszSrc='%s' whole thing is '%s'\n", pszSrc, szNativePath);
     97        /*
     98         * Special case for testing purposes only.
     99         */
     100        if (cchBuf >= PATH_MAX)
     101        {
     102            rc = __libc_back_fsResolve(pszPath, fBackFsFlags, pszBuf, &fInUnixTree);
     103            if (   !(fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE)
     104                && fInUnixTree
     105                && pszBuf)
     106            {
     107                memmove(pszBuf, pszBuf + __libc_gcchUnixRoot, strlen(pszBuf) - __libc_gcchUnixRoot + 1);
     108                LIBC_ASSERTM(*pszBuf== '/', "bogus fInUnixTree flag! pszBuf='%s'\n", pszBuf);
     109            }
     110        }
     111        else
     112            rc = EINVAL;
     113
     114        __libc_back_fsMutexRelease();
    84115    }
    85     __libc_back_fsMutexRelease();
    86 
    87     int cch = strlen(pszSrc) + 1;
    88     if (cch < cchBuf)
    89         memcpy(pszBuf, pszSrc, cchBuf);
    90     else if (!rc)
    91         rc = -ERANGE;
    92116
    93117    if (!rc)
  • branches/libc-0.6/src/emx/src/lib/sys/fs.c

    r3912 r3914  
    10131013            {
    10141014                if ((uintptr_t)(pszUserPath - pachBuffer) > SIZEOF_ACHBUFFER)
    1015                     pszUserPath = strcpy(pachBuffer, pszUserPath);
     1015                {
     1016                    size_t cbUserPath = strlen(pszUserPath) + 1;
     1017                    if (cbUserPath > PATH_MAX)
     1018                    {
     1019                        rcRet = -ENAMETOOLONG;
     1020                        break;
     1021                    }
     1022                    pszUserPath = memcpy(pachBuffer, pszUserPath, cbUserPath);
     1023                }
    10161024                *(char *)(void *)pszUserPath += 'A' - 'a';
    10171025            }
Note: See TracChangeset for help on using the changeset viewer.