From: Roland McGrath Date: Mon, 21 Nov 2005 23:40:54 +0000 (+0000) Subject: 2005-11-21 Roland McGrath X-Git-Tag: elfutils-0.120~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e53b9950e52c08cc61c30755e58523860619b8a;p=thirdparty%2Felfutils.git 2005-11-21 Roland McGrath * linux-kernel-modules.c (dwfl_linux_kernel_module_section_address): Don't leak malloc'd file name. If a /sys/.../sections file is missing and starts with ".init", try the variant with "_init" too; catches PPC64 kernel braindamage. --- diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index c219c330d..39a055f6e 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -373,6 +373,8 @@ dwfl_linux_kernel_module_section_address return ENOMEM; FILE *f = fopen (sysfile, "r"); + free (sysfile); + if (f == NULL) { if (errno == ENOENT) @@ -392,11 +394,29 @@ dwfl_linux_kernel_module_section_address *addr = 0; return DWARF_CB_OK; } + + /* The goofy PPC64 module_frob_arch_sections function tweaks + the section names as a way to control other kernel code's + behavior, and this cruft leaks out into the /sys information. + The file name for ".init*" may actually look like "_init*". */ + + if (!strncmp (secname, ".init", 5)) + { + sysfile = NULL; + asprintf (&sysfile, SECADDRFMT "%s", modname, "_", &secname[1]); + if (sysfile == NULL) + return ENOMEM; + f = fopen (sysfile, "r"); + free (sysfile); + if (f != NULL) + goto ok; + } } return DWARF_CB_ABORT; } + ok: (void) __fsetlocking (f, FSETLOCKING_BYCALLER); int result = (fscanf (f, "%" PRIx64 "\n", addr) == 1 ? 0