From: Mark Wielaard Date: Sat, 28 Dec 2013 11:58:10 +0000 (+0100) Subject: libdwfl: dwfl_linux_proc_find_elf should only return regular files. X-Git-Tag: elfutils-0.158~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ac65261cc5f4b313d4f852e0a7f2b1b91918550b;p=thirdparty%2Felfutils.git libdwfl: dwfl_linux_proc_find_elf should only return regular files. When the dwfl_linux_proc_find_elf callback is used together with the dwfl_linux_proc_report callback that reads /proc/PID/maps files we might see and try to open special character device files that cannot be normally read and processed by libelf (and might hang the library on the initial open or read from the file). Make sure we only try to open and return regular files. Signed-off-by: Mark Wielaard --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 3f9c52554..6c983b2b4 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2013-12-28 Mark Wielaard + + * linux-proc-maps.c (dwfl_linux_proc_find_elf): Don't return special + character device files, only regular files. + 2013-12-24 Mark Wielaard * linux-core-attach.c (core_next_thread): Check whether thread_argp diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c index 8863cc881..b1f8b331a 100644 --- a/libdwfl/linux-proc-maps.c +++ b/libdwfl/linux-proc-maps.c @@ -29,6 +29,7 @@ #include "libdwflP.h" #include #include +#include #include #include #include @@ -345,6 +346,14 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute__ ((unused)), { if (module_name[0] == '/') { + /* When this callback is used together with dwfl_linux_proc_report + then we might see mappings of special character devices. Make + sure we only open and return regular files. Special devices + might hang on open or read. */ + struct stat sb; + if (stat (module_name, &sb) == -1 || (sb.st_mode & S_IFMT) != S_IFREG) + return -1; + int fd = open64 (module_name, O_RDONLY); if (fd >= 0) {