mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
Fix sanity of symbol retrieval code
This commit is contained in:
parent
69f441b5ec
commit
aca4a620ac
@ -255,7 +255,7 @@ MachoSymbolIsLocalDefined (
|
||||
MACH_NLIST_64 *
|
||||
MachoGetLocalDefinedSymbolByName (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST CHAR8 *Name
|
||||
IN CONST CHAR8 *Name
|
||||
);
|
||||
|
||||
/**
|
||||
@ -279,7 +279,7 @@ MachoGetSymbolByIndex64 (
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Symbol Symbol to retrieve the name of.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
@retval symbol name.
|
||||
|
||||
**/
|
||||
CONST CHAR8 *
|
||||
|
||||
@ -768,7 +768,7 @@ InternalRetrieveSymtabs64 (
|
||||
MachoAddress = (UINTN)Context->MachHeader;
|
||||
StringTable = (CHAR8 *)(MachoAddress + Symtab->StringsOffset);
|
||||
|
||||
if (StringTable[(Symtab->StringsSize / sizeof (*StringTable)) - 1] != '\0') {
|
||||
if (Symtab->StringsSize == 0 || StringTable[Symtab->StringsSize - 1] != '\0') {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@ -35,8 +35,9 @@ InternalSymbolIsSane (
|
||||
|
||||
ASSERT (Context->SymbolTable != NULL);
|
||||
ASSERT (Context->Symtab->NumSymbols > 0);
|
||||
ASSERT ((Symbol > Context->SymbolTable)
|
||||
&& (Symbol <= &Context->SymbolTable[Context->Symtab->NumSymbols - 1]));
|
||||
|
||||
ASSERT ((Symbol >= &Context->SymbolTable[0])
|
||||
&& (Symbol < &Context->SymbolTable[Context->Symtab->NumSymbols]));
|
||||
//
|
||||
// Symbol->Section is implicitly verified by MachoGetSectionByIndex64() when
|
||||
// passed to it.
|
||||
@ -226,15 +227,12 @@ MachoGetSymbolByIndex64 (
|
||||
}
|
||||
|
||||
ASSERT (Context->SymbolTable != NULL);
|
||||
ASSERT (Context->Symtab->NumSymbols > 0);
|
||||
|
||||
if (Index < Context->Symtab->NumSymbols) {
|
||||
Symbol = &Context->SymbolTable[Index];
|
||||
if (InternalSymbolIsSane (Context, Symbol)) {
|
||||
return Symbol;
|
||||
}
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -261,9 +259,6 @@ MachoGetSymbolName64 (
|
||||
ASSERT (Context->SymbolTable != NULL);
|
||||
ASSERT (Context->Symtab->StringsSize > Symbol->UnifiedName.StringIndex);
|
||||
|
||||
ASSERT (((Symbol->Type & MACH_N_TYPE_STAB) != 0)
|
||||
|| ((Symbol->Type & MACH_N_TYPE_TYPE) != MACH_N_TYPE_INDR));
|
||||
|
||||
return (Context->StringTable + Symbol->UnifiedName.StringIndex);
|
||||
}
|
||||
|
||||
@ -287,8 +282,10 @@ MachoGetIndirectSymbolName64 (
|
||||
|
||||
ASSERT (Context->SymbolTable != NULL);
|
||||
|
||||
ASSERT (((Symbol->Type & MACH_N_TYPE_STAB) == 0)
|
||||
&& ((Symbol->Type & MACH_N_TYPE_TYPE) == MACH_N_TYPE_INDR));
|
||||
if ((Symbol->Type & MACH_N_TYPE_STAB) != 0
|
||||
|| (Symbol->Type & MACH_N_TYPE_TYPE) != MACH_N_TYPE_INDR) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (Context->Symtab->StringsSize <= Symbol->Value) {
|
||||
return NULL;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user