From: Florian Krohm Date: Sat, 24 Jan 2015 00:02:19 +0000 (+0000) Subject: VG_(am_get_filename) returns a pointer to memory that belongs to the X-Git-Tag: svn/VALGRIND_3_11_0~706 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e70cb7b8518ee56638f85d21ee45a14c972a0b2b;p=thirdparty%2Fvalgrind.git VG_(am_get_filename) returns a pointer to memory that belongs to the address space manager. Callers should neither modify the string nor free it (as the string resides is statically allocated memory). That calls for a const HChar * The type change exposed two bugs. One in m_addrinfo.c and one in m_debuginfo.c. In both cases the returned string could possibly be freed later on. So we need to strdup it first. Now fixed. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14886 --- diff --git a/coregrind/m_addrinfo.c b/coregrind/m_addrinfo.c index 290f279224..7fc777bc40 100644 --- a/coregrind/m_addrinfo.c +++ b/coregrind/m_addrinfo.c @@ -293,7 +293,8 @@ void VG_(describe_addr) ( Addr a, /*OUT*/AddrInfo* ai ) ai->Addr.SegmentKind.segkind = seg->kind; ai->Addr.SegmentKind.filename = NULL; if (seg->kind == SkFileC) - ai->Addr.SegmentKind.filename = VG_(am_get_filename) (seg); + ai->Addr.SegmentKind.filename + = VG_(strdup)("mc.da.skfname", VG_(am_get_filename)(seg)); if (ai->Addr.SegmentKind.filename != NULL) ai->Addr.SegmentKind.filename = VG_(strdup)("mc.da.skfname", diff --git a/coregrind/m_aspacemgr/aspacemgr-linux.c b/coregrind/m_aspacemgr/aspacemgr-linux.c index 15473972a9..224cb33b9a 100644 --- a/coregrind/m_aspacemgr/aspacemgr-linux.c +++ b/coregrind/m_aspacemgr/aspacemgr-linux.c @@ -627,7 +627,7 @@ void VG_(am_show_nsegments) ( Int logLevel, const HChar* who ) has one. The returned name's storage cannot be assumed to be persistent, so the caller should immediately copy the name elsewhere. */ -HChar* VG_(am_get_filename)( NSegment const * seg ) +const HChar* VG_(am_get_filename)( NSegment const * seg ) { Int i; aspacem_assert(seg); diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index e8df79c2d5..ce37e5fa28 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -816,7 +816,7 @@ static ULong di_notify_ACHIEVE_ACCEPT_STATE ( struct _DebugInfo* di ) ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd ) { NSegment const * seg; - HChar* filename; + const HChar* filename; Bool is_rx_map, is_rw_map, is_ro_map; DebugInfo* di; Int actual_fd, oflags; @@ -881,7 +881,7 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd ) Bool quiet = VG_(strstr)(filename, "/var/run/nscd/") != NULL; if (!quiet && VG_(clo_verbosity) > 1) { VG_(memset)(&fake_di, 0, sizeof(fake_di)); - fake_di.fsm.filename = filename; + fake_di.fsm.filename = ML_(dinfo_strdup)("di.debuginfo.nmm", filename); ML_(symerr)(&fake_di, True, "failed to stat64/stat this file"); } return 0; @@ -986,7 +986,8 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd ) if (sr_Err(fd) != VKI_EACCES) { DebugInfo fake_di; VG_(memset)(&fake_di, 0, sizeof(fake_di)); - fake_di.fsm.filename = filename; + fake_di.fsm.filename = ML_(dinfo_strdup)("di.debuginfo.nmm", + filename); ML_(symerr)(&fake_di, True, "can't open file to inspect ELF header"); } @@ -1005,7 +1006,7 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd ) if (sr_isError(preadres)) { DebugInfo fake_di; VG_(memset)(&fake_di, 0, sizeof(fake_di)); - fake_di.fsm.filename = filename; + fake_di.fsm.filename = ML_(dinfo_strdup)("di.debuginfo.nmm", filename); ML_(symerr)(&fake_di, True, "can't read file to inspect ELF header"); return 0; } diff --git a/include/pub_tool_aspacemgr.h b/include/pub_tool_aspacemgr.h index 05cc1d344e..a10e21fb4c 100644 --- a/include/pub_tool_aspacemgr.h +++ b/include/pub_tool_aspacemgr.h @@ -144,7 +144,7 @@ extern NSegment const * VG_(am_find_nsegment) ( Addr a ); elsewhere. This may return NULL if the file name is not known or for arbitrary other implementation-dependent reasons, so callers need to be able to handle a NULL return value. */ -extern HChar* VG_(am_get_filename)( NSegment const * ); +extern const HChar* VG_(am_get_filename)( NSegment const * ); /* Is the area [start .. start+len-1] validly accessible by the client with at least the permissions 'prot' ? To find out diff --git a/memcheck/mc_leakcheck.c b/memcheck/mc_leakcheck.c index 0c0bb53f48..4e6e28e67d 100644 --- a/memcheck/mc_leakcheck.c +++ b/memcheck/mc_leakcheck.c @@ -1634,7 +1634,7 @@ static void scan_memory_root_set(Addr searched, SizeT szB) // memory by explicitly mapping /dev/zero. if (seg->kind == SkFileC && (VKI_S_ISCHR(seg->mode) || VKI_S_ISBLK(seg->mode))) { - HChar* dev_name = VG_(am_get_filename)( seg ); + const HChar* dev_name = VG_(am_get_filename)( seg ); if (dev_name && 0 == VG_(strcmp)(dev_name, "/dev/zero")) { // Don't skip /dev/zero. } else {