From 2fca25d4c0e4d7e8f7d26621757f991d1163f342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Wed, 4 Jan 2023 15:07:01 +0100 Subject: [PATCH] Fix segmentation fault if a NOBITS section is specified for output --- src/elfpatch.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/elfpatch.c b/src/elfpatch.c index 7e9c3a0..978f8e6 100644 --- a/src/elfpatch.c +++ b/src/elfpatch.c @@ -534,6 +534,11 @@ int elf_patch_write_crcs_to_section(elfpatch_handle_t *ep, const char *section, /* Get data object of section */ output_sec_data = elf_getdata(output_section->scn, NULL); sec_bytes = (uint8_t *)output_sec_data->d_buf; + if (!sec_bytes) { + print_err("Output section '%s' does not contain loadable data. It has to be allocated in the ELF file\n", + section); + goto ret_err; + } /* Check the start and end magics */ if (check_start_magic) {