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: Don't report and abort on non-file mappings in maps.


proc_maps_report, used for -p or -M, could report modules with names
that were not absolute file names (and not the special vdso marker).
dwfl_linux_proc_find_elf would abort on such names. This isn't a very
nice thing to do in a library. Make sure only real (absolute) file
mappings are reported and don't abort when unexpected file names are
found, just report failure.

Test case with some examples as found in Linux /proc/PID/maps added.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog         |    6 +++++
 libdwfl/linux-proc-maps.c |    3 +-
 tests/ChangeLog           |    8 ++++++-
 tests/Makefile.am         |    4 +-
 tests/run-unstrip-M.sh    |   51 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 67 insertions(+), 5 deletions(-)
 create mode 100755 tests/run-unstrip-M.sh

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 4d119fd..b6729c7 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2013-10-15  Mark Wielaard  <mjw@redhat.com>
+
+	* linux-proc-maps.c (proc_maps_report): Ignore non-absolute file
+	mappings.
+	(dwfl_linux_proc_find_elf): Don't abort, just return failure.
+
 2013-09-12  Mark Wielaard  <mjw@redhat.com>
 
 	* cu.c (intern_cu): If dwarf_offdie fails free cu.
diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c
index 10946b9..4eaccdb 100644
--- a/libdwfl/linux-proc-maps.c
+++ b/libdwfl/linux-proc-maps.c
@@ -232,7 +232,7 @@ proc_maps_report (Dwfl *dwfl, FILE *f, GElf_Addr sysinfo_ehdr, pid_t pid)
 	}
 
       char *file = line + nread + strspn (line + nread, " \t");
-      if (file[0] == '\0' || (ino == 0 && dmajor == 0 && dminor == 0))
+      if (file[0] != '/' || (ino == 0 && dmajor == 0 && dminor == 0))
 	/* This line doesn't indicate a file mapping.  */
 	continue;
 
@@ -373,7 +373,6 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute__ ((unused)),
       return -1;
     }
 
-  abort ();
   return -1;
 }
 INTDEF (dwfl_linux_proc_find_elf)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index db248dc..f6b794b 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2013-10-15  Mark Wielaard  <mjw@redhat.com>
+
+	* run-unstrip-M.sh: New test.
+	* Makefile.am (TESTS): Add run-unstrip-M.sh.
+	(EXTRA_DIST): Likewise.
+
 2013-10-06  Mark Wielaard  <mjw@redhat.com>
 
 	* run-addrcfi.sh: Remove nop from expected ppc and ppc64
@@ -7,7 +13,7 @@
 
 	* typeiter2.c: New file, reversing typeiter.c.
 	* run-typeiter.sh: Also run typeiter2.
-	* Makefile.am (ckeck_PROGRAMS): Add typeiter2.
+	* Makefile.am (check_PROGRAMS): Add typeiter2.
 	(typeiter2_LDADD): New variable.
 
 2013-09-26  Petr Machata  <pmachata@redhat.com>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index de98e45..f3c56bf 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -65,7 +65,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
 	run-strip-test3.sh run-strip-test4.sh run-strip-test5.sh \
 	run-strip-test6.sh run-strip-test7.sh run-strip-test8.sh \
 	run-strip-groups.sh run-strip-reloc.sh \
-	run-unstrip-test.sh run-unstrip-test2.sh \
+	run-unstrip-test.sh run-unstrip-test2.sh run-unstrip-M.sh \
 	run-ecp-test.sh run-ecp-test2.sh run-alldts.sh \
 	run-elflint-test.sh run-elflint-self.sh run-ranlib-test.sh \
 	run-ranlib-test2.sh run-ranlib-test3.sh run-ranlib-test4.sh \
@@ -125,7 +125,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
 	     run-strip-test7.sh run-strip-test8.sh run-strip-groups.sh \
 	     run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \
 	     hello_ppc64.ko.bz2 hello_s390.ko.bz2 \
-	     run-unstrip-test.sh run-unstrip-test2.sh \
+	     run-unstrip-test.sh run-unstrip-test2.sh run-unstrip-M.sh\
 	     run-elflint-self.sh run-ranlib-test.sh run-ranlib-test2.sh \
 	     run-ranlib-test3.sh run-ranlib-test4.sh \
 	     run-addrscopes.sh run-strings-test.sh run-funcscopes.sh \
diff --git a/tests/run-unstrip-M.sh b/tests/run-unstrip-M.sh
new file mode 100755
index 0000000..614a8aa
--- /dev/null
+++ b/tests/run-unstrip-M.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2013 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# Linux /proc/PID/maps file with some non-file entries (and fake exe/lib names).
+tempfiles testmaps
+cat > testmaps <<EOF
+00400000-024aa000 r-xp 00000000 08:02 159659                             /opt/TestBins/bin/arwijn
+026aa000-026b2000 rwxp 020aa000 08:02 159659                             /opt/TestBins/bin/arwijn
+026b2000-026bf000 rwxp 00000000 00:00 0
+0335a000-03e6f000 rwxp 00000000 00:00 0                                  [heap]
+2b7b38282000-2b7b38302000 rwxs 00000000 00:06 493872                     socket:[493872]
+2b7b38302000-2b7b38312000 rwxs 00000000 00:06 493872                     socket:[493872]
+2b7b38312000-2b7b38b12000 r-xs 00000000 00:06 493872                     socket:[493872]
+2b7b38b12000-2b7b38b22000 rwxs 00000000 00:06 493872                     socket:[493872]
+2b7b38b22000-2b7b39322000 rwxs 00000000 00:06 493872                     socket:[493872]
+2b7b4439f000-2b7b45ea1000 rwxp 00000000 00:00 0
+7f31e7d9f000-7f31e7f29000 r-xp 00000000 fd:00 917531                     /lib64/libc-1.13.so
+7f31e7f29000-7f31e8128000 ---p 0018a000 fd:00 917531                     /lib64/libc-1.13.so
+7f31e8128000-7f31e812c000 r--p 00189000 fd:00 917531                     /lib64/libc-1.13.so
+7f31e812c000-7f31e812d000 rw-p 0018d000 fd:00 917531                     /lib64/libc-1.13.so
+7f31e812d000-7f31e8132000 rw-p 00000000 00:00 0 
+7f31ea3f9000-7f31ea3fc000 rw-s 00000000 00:09 3744                       anon_inode:kvm-vcpu
+7f31ea3fc000-7f31ea3ff000 rw-s 00000000 00:09 3744                       anon_inode:kvm-vcpu
+7f31ea400000-7f31ea402000 rw-p 00000000 00:00 0 
+7fff26cf7000-7fff26d0c000 rwxp 00000000 00:00 0                          [stack]
+7fff26dff000-7fff26e00000 r-xp 00000000 00:00 0                          [vdso]
+ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
+EOF
+
+testrun_compare ${abs_top_builddir}/src/unstrip -n -M testmaps <<\EOF
+0x400000+0x22b2000 - - - /opt/TestBins/bin/arwijn
+0x7f31e7d9f000+0x38e000 - - - /lib64/libc-1.13.so
+EOF
+
+exit 0
-- 
1.7.1


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