From ba2765fb49ef04d47e8bb30c74d7b25bca2f4810 Mon Sep 17 00:00:00 2001 From: Nick Owens Date: Tue, 31 Dec 2024 13:53:38 -0800 Subject: [PATCH] runtime: add trivial mmap failure check --- src/runtime/runtime.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 9846786..8d30f32 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -321,6 +321,11 @@ bool appimage_get_elf_section_offset_and_length(const char* fname, const char* s data = mmap(NULL, map_size, PROT_READ, MAP_SHARED, fd, 0); close(fd); + if (data == MAP_FAILED) { + fprintf(stderr, "Failed to mmap file %s: %s\n", fname, strerror(errno)); + return false; + } + // this trick works as both 32 and 64 bit ELF files start with the e_ident[EI_NINDENT] section unsigned char class = data[EI_CLASS];