]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Fix fd leak/closing wrong fd after dwfl_core_file_report()
authorOmar Sandoval <osandov@fb.com>
Mon, 5 Aug 2019 10:40:05 +0000 (03:40 -0700)
committerMark Wielaard <mark@klomp.org>
Fri, 9 Aug 2019 20:31:18 +0000 (22:31 +0200)
dwfl_segment_report_module() (used only by dwfl_core_file_report())
opens a file descriptor and/or an Elf handle, reports a module, and
assigns mod->main.elf. However, it doesn't assign mod->main.fd, so it is
left as 0. This causes two problems:

1. We leak the file descriptor for the module.
2. When we free the module, we close file descriptor 0 (stdin).

Fix it by assigning mod->main.fd.

Signed-off-by: Omar Sandoval <osandov@fb.com>
libdwfl/ChangeLog
libdwfl/dwfl_segment_report_module.c

index 7c9a018b855a2c09617294955b2e8878552c4b7b..8cbe90c95d00d470ac0b0acdecbbed404a590eae 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-05  Omar Sandoval  <osandov@fb.com>
+
+       * dwfl_segment_report_module.c (dwfl_segment_report_module): Assign
+       mod->main.fd.
+
 2019-04-28  Mark Wielaard  <mark@klomp.org>
 
        * frame_unwind.c (expr_eval): Make sure we left shift a unsigned
index 76ba150685c751684e110640aed3ec5f147a98ba..430e13d57ce82d8f54b3a04e22bcbf0dd9fe3bb0 100644 (file)
@@ -967,6 +967,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
     {
       /* Install the file in the module.  */
       mod->main.elf = elf;
+      mod->main.fd = fd;
       elf = NULL;
       fd = -1;
       mod->main.vaddr = module_start - bias;