summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2019-08-05 03:40:05 -0700
committerMark Wielaard <mark@klomp.org>2019-08-09 22:31:18 +0200
commitd37f6ea7e3e544e27b6067405a6b5ab0a31a99c8 (patch)
tree0639315f0dd20daf2a3e46b146db9bc39721bcd8
parent1b1433d5670b75c4bd5c9b598e0b00fba6e82d90 (diff)
downloadelfutils-d37f6ea7e3e544e27b6067405a6b5ab0a31a99c8.tar.gz
libdwfl: Fix fd leak/closing wrong fd after dwfl_core_file_report()
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>
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/dwfl_segment_report_module.c1
2 files changed, 6 insertions, 0 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 7c9a018b..8cbe90c9 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -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
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 76ba1506..430e13d5 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -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;