Browse Source

+ wasm internal object reader: validate that relocations that should point to a SYMTAB_FUNCTION entry, actually point to such entry

Nikolay Nikolov 1 year ago
parent
commit
3071ae231a
1 changed files with 9 additions and 0 deletions
  1. 9 0
      compiler/ogwasm.pas

+ 9 - 0
compiler/ogwasm.pas

@@ -2678,6 +2678,15 @@ implementation
                         InputError('R_WASM_SECTION_OFFSET_I32 must point to a SYMTAB_SECTION symbol');
                         InputError('R_WASM_SECTION_OFFSET_I32 must point to a SYMTAB_SECTION symbol');
                         exit;
                         exit;
                       end;
                       end;
+                    if (RelocType in [
+                          R_WASM_FUNCTION_INDEX_LEB,
+                          R_WASM_TABLE_INDEX_SLEB,
+                          R_WASM_TABLE_INDEX_I32,
+                          R_WASM_FUNCTION_OFFSET_I32]) and (SymbolTable[RelocIndex].SymKind<>SYMTAB_FUNCTION) then
+                      begin
+                        InputError('Relocation must point to a SYMTAB_FUNCTION symbol');
+                        exit;
+                      end;
                   end;
                   end;
               if AReader.Pos<>(SectionStart+SectionSize) then
               if AReader.Pos<>(SectionStart+SectionSize) then
                 begin
                 begin