]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
VG_(am_get_filename) returns a pointer to memory that belongs to the
authorFlorian Krohm <florian@eich-krohm.de>
Sat, 24 Jan 2015 00:02:19 +0000 (00:02 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sat, 24 Jan 2015 00:02:19 +0000 (00:02 +0000)
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

coregrind/m_addrinfo.c
coregrind/m_aspacemgr/aspacemgr-linux.c
coregrind/m_debuginfo/debuginfo.c
include/pub_tool_aspacemgr.h
memcheck/mc_leakcheck.c

index 290f27922422e10c16598d9fb5e94dd15313a9d8..7fc777bc40380f7933b9b7201ccd03dfa37570fe 100644 (file)
@@ -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",
index 15473972a9c7f6598ef48e5453a4eac7f762ad8e..224cb33b9ac9a0c920b6029d3ac6ea87fb559049 100644 (file)
@@ -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);
index e8df79c2d57cb8143b780d2b9c6a5d2d3d9a8fc5..ce37e5fa28cee61c76f433fccc414b2896c6dbca 100644 (file)
@@ -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;
    }
index 05cc1d344e0597eab1b7e75df379267f630cfcd8..a10e21fb4c03e30dbe5d69e2e7fb6d545fb5a18c 100644 (file)
@@ -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
index 0c0bb53f48afc4bc6d659fab26ad63c7cf7150c4..4e6e28e67daae03b80e1d457da33968a26198754 100644 (file)
@@ -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 {