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 10/17] libdwfl: Don't stack allocate alternate_name in dwfl_linux_kernel_find_elf.


Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog              | 5 +++++
 libdwfl/linux-kernel-modules.c | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index d06d34d..ef03973 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
 2015-05-19  Mark Wielaard  <mjw@redhat.com>
 
+	* linux-kernel-modules.c (dwfl_linux_kernel_find_elf): malloc and
+	free alternate_name.
+
+2015-05-19  Mark Wielaard  <mjw@redhat.com>
+
 	* linux-kernel-modules.c (dwfl_linux_kernel_report_offline): Don't
 	stack allocate name. Only change chars up to suffix.
 
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index 66b3ab6..f61754c 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -707,7 +707,12 @@ dwfl_linux_kernel_find_elf (Dwfl_Module *mod,
      two files when either a '_' or '-' appears in a module name, one using
      only '_' and one only using '-'.  */
 
-  char alternate_name[namelen + 1];
+  char *alternate_name = malloc (namelen + 1);
+  if (alternate_name == NULL)
+    {
+      free (modulesdir[0]);
+      return ENOMEM;
+    }
   inline bool subst_name (char from, char to)
     {
       const char *n = memchr (module_name, from, namelen);
@@ -757,6 +762,7 @@ dwfl_linux_kernel_find_elf (Dwfl_Module *mod,
 	      *file_name = strdup (f->fts_path);
 	      fts_close (fts);
 	      free (modulesdir[0]);
+	      free (alternate_name);
 	      if (fd < 0)
 		free (*file_name);
 	      else if (*file_name == NULL)
@@ -782,6 +788,7 @@ dwfl_linux_kernel_find_elf (Dwfl_Module *mod,
 
   fts_close (fts);
   free (modulesdir[0]);
+  free (alternate_name);
   errno = error;
   return -1;
 }
-- 
1.8.3.1


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