This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libdwfl: Fix memory leak in __libdwfl_open_by_build_id.


commit c57829 introduced a memory leak by passing the path string to
strsep. strsep will change the given pointer and set it to NULL eventually.
Causing the original pointer to leak. Fix by passing a copy of the pointer
to strsep.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog                | 5 +++++
 libdwfl/dwfl_build_id_find_elf.c | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index f4e7484..4de3832 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2015-06-01  Mark Wielaard  <mjw@redhat.com>
+
+	* dwfl_build_id_find_elf.c (__libdwfl_open_by_build_id): Copy path
+	pointer before passing to strsep.
+
 2015-05-30  Mark Wielaard  <mjw@redhat.com>
 
 	* link_map.c (check32): Use read_4ubyte_unaligned_noncvt to read
diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c
index 215782a..99a5059 100644
--- a/libdwfl/dwfl_build_id_find_elf.c
+++ b/libdwfl/dwfl_build_id_find_elf.c
@@ -73,7 +73,8 @@ __libdwfl_open_by_build_id (Dwfl_Module *mod, bool debug, char **file_name,
 
   int fd = -1;
   char *dir;
-  while (fd < 0 && (dir = strsep (&path, ":")) != NULL)
+  char *paths = path;
+  while (fd < 0 && (dir = strsep (&paths, ":")) != NULL)
     {
       if (dir[0] == '+' || dir[0] == '-')
 	++dir;
-- 
1.8.3.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]