Changeset 4879 for trunk/src


Ignore:
Timestamp:
Jan 8, 2001, 7:04:23 PM (25 years ago)
Author:
bird
Message:

Fixed two bugs in the ldrCheckInternalName replacement which are
relally features/bugs in OS/2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/ldr/myldrCheckInternalName.cpp

    r4779 r4879  
    1 /* $Id: myldrCheckInternalName.cpp,v 1.1 2000-12-11 06:31:52 bird Exp $
     1/* $Id: myldrCheckInternalName.cpp,v 1.2 2001-01-08 18:04:23 bird Exp $
    22 *
    33 * ldrCheckInternalName - ldrCheckInternalName replacement with support for
     
    5757 *
    5858 * @remark      This function will have to change slightly when we're starting to
    59  *              support ELF shared libraries.
     59 *              support ELF shared libraries (ie. .so-files).
    6060 */
    6161ULONG LDRCALL myldrCheckInternalName(PMTE pMTE)
     
    8181    PCHAR   pachExt;                    /* Pointer to the extention part of pachFilename. (not dot!) */
    8282    int     cchExt;                     /* Length of the extention part of pachFilename. (not dot!) */
    83     PSMTE   pSMTE;                      /* Pointer to swap mte. */
     83    APIRET  rc;                         /* Return code. */
    8484
    85     /* Return successfully if not library module. */
     85
     86    /*
     87     * Return successfully if not library module.
     88     */
    8689    if (!(pMTE->mte_flags1 & LIBRARYMOD))
    8790        return NO_ERROR;
    8891
    89     /* Uppercase and parse filename in ldrpFileNameBuf */
     92
     93    /*
     94     * Uppercase and parse filename in ldrpFileNameBuf
     95     */
    9096    cchName = (int)ldrGetFileName2(ldrpFileNameBuf, (PCHAR*)SSToDS(&pachName), (PCHAR*)SSToDS(&pachExt));
    9197    cchExt = (pachExt) ? strlen(pachExt) : 0;
    9298    ldrUCaseString(pachName, cchName + cchExt + 1);
    93     if ((pMTE->mte_flags1 & CLASS_MASK) == CLASS_GLOBAL && (cchExt != 3 || memcmp(pachExt, "DLL", 3)))
    94         cchName += cchExt + 1;          /* Internal name includes extention if the extention is not .DLL! */
    95                                         /* If no extention the '.' should still be there! */
    9699
    97     /* Compare the internal name with the filename and return accordingly. */
    98     pSMTE = pMTE->mte_swapmte;
    99     #ifdef DEBUG
    100     APIRET rc =
    101     #else
    102     return
    103     #endif
    104             (   pSMTE->smte_restab != NULL
    105              && *(PCHAR)pSMTE->smte_restab == cchName
    106              && (cchExt == 0 && (pMTE->mte_flags1 & CLASS_MASK) == CLASS_GLOBAL
    107                  ?      !memcmp(pachName, (PCHAR)pSMTE->smte_restab + 1, cchName - 1)   /* No extention. Internal name should have a signle dot at the end then. */
    108                     &&  ((PCHAR)pSMTE->smte_restab)[cchName] == '.'
    109                  : !memcmp(pachName, (PCHAR)pSMTE->smte_restab + 1, cchName)            /* Extention, .DLL or not global class. */
    110                 )
    111              )
    112             ? NO_ERROR
    113             : ERROR_INVALID_NAME;
    114     #ifdef DEBUG
     100
     101    /*
     102     * Do the compare - DllFix case or standard case.
     103     */
     104    if (cchName > 8
     105        || (   (pMTE->mte_flags1 & CLASS_MASK) == CLASS_GLOBAL
     106            && (cchExt != 3 || strcmp(pachExt, "DLL"))  /* Extention != DLL. */
     107            )
     108        )
     109    {   /*
     110         * Rules for long DLL names or GLOBAL dlls with extention <> DLL:
     111         *  1. If DLL extention, the internal name don't need to have an extention,
     112         *     but it could have.
     113         *  2. If not DLL extention, then internal name must have an extention.
     114         *  3. If no extetion the internal name should end with a '.'.
     115         */
     116        PCHAR   pachResName = (PCHAR)pMTE->mte_swapmte->smte_restab;
     117
     118        if (pachExt != NULL && cchExt == 3 && !memcmp(pachExt, "DLL", 3))   /* DLL extention. */
     119        {   /* (1) */
     120            rc =(   (   *pachResName == cchName
     121                     || *pachResName == cchName + cchExt + 1)
     122                 && !memcmp(pachResName + 1, pachName, *pachResName)
     123                 );
     124        }
     125        else if (cchExt > 0)            /* Extention. */
     126        {   /* (2) */
     127            rc =(   *pachResName == cchName + cchExt + 1
     128                 && !memcmp(pachResName + 1, pachName, *pachResName)
     129                 );
     130        }                               /* No extetion. */
     131        else
     132        {   /* (3) */
     133            rc =(   *pachResName == cchName + 1
     134                 && pachResName[cchName + 1] == '.'
     135                 && !memcmp(pachResName + 1, pachName, cchName)
     136                 );
     137        }
     138        rc = (rc) ? NO_ERROR : ERROR_INVALID_NAME;
     139    }
     140    else
     141    {   /*
     142         * Rules for short DLL names. ( < 8 chars):
     143         *  1.  The internal name must match the DLL name.
     144         *  2b. If the DLL name is 8 chars the internal name could have extra chars (but we don't check).
     145         *          (This is a feature/bug.)
     146         *  2a. If the DLL name is less than 8 chars the internal name should match exactly.
     147         */
     148        #if 0
     149            /* This was the way it should be implemented, but code is buggy.
     150             * Current code works like this:
     151             *  rc =(   memcmp(pachName, pMTE->mte_modname, cchName)
     152             *       && (   cchName == 8
     153             *           || pMTE->mte_modname[cchName] == '\0'
     154             *           )
     155             *       ) ? ERROR_INVALID_NAME : NO_ERROR;
     156             *
     157             * This is so old that it has become an persistant bug in some ways.
     158             * The correct check will break Lotus Freelance for example.
     159             * But, the applications which are broken all seems to include the
     160             * .DLL extention in the internal name (and have length which is
     161             * shorter than 8 chars).
     162             * So, a correction will simply be to remove any .DLL extention
     163             * of the internal name before setting it ldrCreateMte. This fix
     164             * could always be done here too.
     165             *
     166             * BTW. I managed to exploit this bug to replace doscall1.dll.
     167             *      Which is very nasty!
     168             */
     169        rc =(   !memcmp(pachName, pMTE->mte_modname, cchName)   /* (1) */
     170             && (   cchName == 8                                /* (2a) */
     171                 || pMTE->mte_modname[cchName] == '\0'          /* (2b) */
     172                 )
     173             ) ? NO_ERROR : ERROR_INVALID_NAME;
     174        #else
     175        /* For the issue of compatibly with the bug we'll call the real function. */
     176        rc = ldrCheckInternalName(pMTE);
     177        #endif
     178    }
     179
     180
     181    /*
     182     * Log answer and return it.
     183     */
    115184    kprintf(("myldrCheckInternalName: pMTE=0x%08x intname=%.*s path=%s rc=%d\n",
    116185             pMTE, *(PCHAR)pMTE->mte_swapmte->smte_restab, (PCHAR)pMTE->mte_swapmte->smte_restab + 1, ldrpFileNameBuf, rc));
     186
    117187    return rc;
    118     #endif
    119188}
    120189
Note: See TracChangeset for help on using the changeset viewer.