- Timestamp:
- Jan 8, 2001, 7:04:23 PM (25 years ago)
- 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:52bird Exp $1 /* $Id: myldrCheckInternalName.cpp,v 1.2 2001-01-08 18:04:23 bird Exp $ 2 2 * 3 3 * ldrCheckInternalName - ldrCheckInternalName replacement with support for … … 57 57 * 58 58 * @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). 60 60 */ 61 61 ULONG LDRCALL myldrCheckInternalName(PMTE pMTE) … … 81 81 PCHAR pachExt; /* Pointer to the extention part of pachFilename. (not dot!) */ 82 82 int cchExt; /* Length of the extention part of pachFilename. (not dot!) */ 83 PSMTE pSMTE; /* Pointer to swap mte. */83 APIRET rc; /* Return code. */ 84 84 85 /* Return successfully if not library module. */ 85 86 /* 87 * Return successfully if not library module. 88 */ 86 89 if (!(pMTE->mte_flags1 & LIBRARYMOD)) 87 90 return NO_ERROR; 88 91 89 /* Uppercase and parse filename in ldrpFileNameBuf */ 92 93 /* 94 * Uppercase and parse filename in ldrpFileNameBuf 95 */ 90 96 cchName = (int)ldrGetFileName2(ldrpFileNameBuf, (PCHAR*)SSToDS(&pachName), (PCHAR*)SSToDS(&pachExt)); 91 97 cchExt = (pachExt) ? strlen(pachExt) : 0; 92 98 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! */96 99 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 */ 115 184 kprintf(("myldrCheckInternalName: pMTE=0x%08x intname=%.*s path=%s rc=%d\n", 116 185 pMTE, *(PCHAR)pMTE->mte_swapmte->smte_restab, (PCHAR)pMTE->mte_swapmte->smte_restab + 1, ldrpFileNameBuf, rc)); 186 117 187 return rc; 118 #endif119 188 } 120 189
Note:
See TracChangeset
for help on using the changeset viewer.