From 22625ba38d9326aba27dea61edf6ae53c11c0587 Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Fri, 22 Nov 2024 11:15:14 -0800 Subject: [PATCH] Fix crash when relocation section is malformed Found by a fuzzer Signed-off-by: Dave Thaler --- src/asm_files.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/asm_files.cpp b/src/asm_files.cpp index 27e987e7f..eb01d4446 100644 --- a/src/asm_files.cpp +++ b/src/asm_files.cpp @@ -245,6 +245,10 @@ static void append_subprograms(raw_program& prog, const vector& pro auto [symbol_name, section_index] = get_symbol_name_and_section_index(symbols, reloc.relocation_entry_index); + if (section_index >= reader.sections.size()) { + throw UnmarshalError("Invalid section index " + std::to_string(section_index) + " at source offset " + + std::to_string(reloc.source_offset)); + } ELFIO::section& subprogram_section = *reader.sections[section_index]; auto subprogram = read_subprogram(subprogram_section, symbols, symbol_name); prog.prog.insert(prog.prog.end(), subprogram.begin(), subprogram.end());