diff options
author | Dave Watson <davejwatson@fb.com> | 2017-08-16 10:59:32 -0700 |
---|---|---|
committer | Dave Watson <davejwatson@fb.com> | 2017-08-16 10:59:32 -0700 |
commit | 2acc55815c60a15723cbbb4db5ede9c3c77b3cad (patch) | |
tree | 0694ebc9fc0ec55e5cf8bd4c3ff5def4d6c08bf9 | |
parent | 57257060c9d56cf9d1a499d71e3ca1eb51cd279d (diff) | |
download | libunwind-2acc55815c60a15723cbbb4db5ede9c3c77b3cad.tar.gz |
elf: Don't use .gnu_debuglink if it doesn't exist
Some binaries contain a gnu_debuglink, even though the actual
file it points to doesn't exist. In those cases, continue
to use the existing binary instead of trying to load the debuglink file.
-rw-r--r-- | src/elfxx.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/elfxx.c b/src/elfxx.c index 685cf2f5..48a08cdc 100644 --- a/src/elfxx.c +++ b/src/elfxx.c @@ -386,6 +386,8 @@ elf_w (load_debuglink) (const char* file, struct elf_image *ei, int is_local) { int ret; Elf_W (Shdr) *shdr; + Elf_W (Ehdr) *prev_image = ei->image; + off_t prev_size = ei->size; if (!ei->image) { @@ -420,7 +422,6 @@ elf_w (load_debuglink) (const char* file, struct elf_image *ei, int is_local) if (memchr (linkbuf, 0, shdr->sh_size) == NULL) return 0; - munmap (ei->image, ei->size); ei->image = NULL; Debug(1, "Found debuglink section, following %s\n", linkbuf); @@ -456,6 +457,19 @@ elf_w (load_debuglink) (const char* file, struct elf_image *ei, int is_local) ret = elf_w (load_debuglink) (newname, ei, -1); } + if (ret == -1) + { + /* No debuglink file found even though .gnu_debuglink existed */ + ei->image = prev_image; + ei->size = prev_size; + + return 0; + } + else + { + munmap (prev_image, prev_size); + } + return ret; } } |