From 1ffa32eed68b02c79dfc3b5b113344ef62df7b83 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Mon, 3 Aug 2009 17:00:34 +0000 Subject: gdb/ Fix memory corruption on reread of file through a symbolic link. * symfile.c (find_separate_debug_file): Initialize CANON_NAME earlier. Allocate DEBUGFILE with length based on CANON_NAME. Free CANON_NAME on all the return paths. --- gdb/ChangeLog | 8 ++++++++ gdb/symfile.c | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'gdb') diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4bc40b4..42c5a2d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2009-08-03 Richard Guenther + Jan Kratochvil + + Fix memory corruption on reread of file through a symbolic link. + * symfile.c (find_separate_debug_file): Initialize CANON_NAME earlier. + Allocate DEBUGFILE with length based on CANON_NAME. Free CANON_NAME on + all the return paths. + 2009-08-03 Jim Ingham Vladimir Prus diff --git a/gdb/symfile.c b/gdb/symfile.c index 36480c1..4bdab91 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1388,8 +1388,14 @@ find_separate_debug_file (struct objfile *objfile) gdb_assert (i >= 0 && IS_DIR_SEPARATOR (dir[i])); dir[i+1] = '\0'; + /* Set I to max (strlen (canon_name), strlen (dir)). */ + canon_name = lrealpath (dir); + i = strlen (dir); + if (canon_name && strlen (canon_name) > i) + i = strlen (canon_name); + debugfile = alloca (strlen (debug_file_directory) + 1 - + strlen (dir) + + i + strlen (DEBUG_SUBDIRECTORY) + strlen ("/") + strlen (basename) @@ -1403,6 +1409,7 @@ find_separate_debug_file (struct objfile *objfile) { xfree (basename); xfree (dir); + xfree (canon_name); return xstrdup (debugfile); } @@ -1416,6 +1423,7 @@ find_separate_debug_file (struct objfile *objfile) { xfree (basename); xfree (dir); + xfree (canon_name); return xstrdup (debugfile); } @@ -1429,12 +1437,12 @@ find_separate_debug_file (struct objfile *objfile) { xfree (basename); xfree (dir); + xfree (canon_name); return xstrdup (debugfile); } /* If the file is in the sysroot, try using its base path in the global debugfile directory. */ - canon_name = lrealpath (dir); if (canon_name && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0 && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)])) @@ -1449,6 +1457,7 @@ find_separate_debug_file (struct objfile *objfile) xfree (canon_name); xfree (basename); xfree (dir); + xfree (canon_name); return xstrdup (debugfile); } } -- cgit v1.1