diff options
author | Rummskartoffel <Rummskartoffel@protonmail.com> | 2022-01-16 14:24:21 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-18 09:08:14 +0100 |
commit | 487377d1d72f66a2cbfc32cbdb1b1bbe216c4014 (patch) | |
tree | dc1820506afe48dc725052afb73d08264c251f2a /Userland/Utilities/disasm.cpp | |
parent | 0aa5725f72b1aae3bfcd653305ac43ca8fc082f4 (diff) | |
download | serenity-487377d1d72f66a2cbfc32cbdb1b1bbe216c4014.zip |
disasm: Don't fail when trying to disassemble empty files
Given an empty file, disasm would try to create a zero-size memory
mapping of that file, which would fail with EINVAL.
Diffstat (limited to 'Userland/Utilities/disasm.cpp')
-rw-r--r-- | Userland/Utilities/disasm.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Userland/Utilities/disasm.cpp b/Userland/Utilities/disasm.cpp index 02ccda6089..93ecd74845 100644 --- a/Userland/Utilities/disasm.cpp +++ b/Userland/Utilities/disasm.cpp @@ -10,6 +10,7 @@ #include <AK/Vector.h> #include <LibCore/ArgsParser.h> #include <LibCore/MappedFile.h> +#include <LibCore/System.h> #include <LibELF/Image.h> #include <LibMain/Main.h> #include <LibX86/Disassembler.h> @@ -27,7 +28,14 @@ ErrorOr<int> serenity_main(Main::Arguments args) args_parser.add_positional_argument(path, "Path to i386 binary file", "path"); args_parser.parse(args); - auto file = TRY(Core::MappedFile::map(path)); + RefPtr<Core::MappedFile> file; + u8 const* asm_data = nullptr; + size_t asm_size = 0; + if ((TRY(Core::System::stat(path))).st_size > 0) { + file = TRY(Core::MappedFile::map(path)); + asm_data = static_cast<u8 const*>(file->data()); + asm_size = file->size(); + } struct Symbol { size_t value; @@ -41,8 +49,6 @@ ErrorOr<int> serenity_main(Main::Arguments args) }; Vector<Symbol> symbols; - u8 const* asm_data = static_cast<u8 const*>(file->data()); - size_t asm_size = file->size(); size_t file_offset = 0; Vector<Symbol>::Iterator current_symbol = symbols.begin(); OwnPtr<X86::ELFSymbolProvider> symbol_provider; // nullptr for non-ELF disassembly. |