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.
This commit is contained in:
Jan Kratochvil 2009-08-03 17:00:34 +00:00
parent 004fb7809c
commit 1ffa32eed6
2 changed files with 19 additions and 2 deletions

View file

@ -1,3 +1,11 @@
2009-08-03 Richard Guenther <rguenther@suse.de>
Jan Kratochvil <jan.kratochvil@redhat.com>
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 <jingham@apple.com> 2009-08-03 Jim Ingham <jingham@apple.com>
Vladimir Prus <vladimir@codesourcery.com> Vladimir Prus <vladimir@codesourcery.com>

View file

@ -1388,8 +1388,14 @@ find_separate_debug_file (struct objfile *objfile)
gdb_assert (i >= 0 && IS_DIR_SEPARATOR (dir[i])); gdb_assert (i >= 0 && IS_DIR_SEPARATOR (dir[i]));
dir[i+1] = '\0'; 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 debugfile = alloca (strlen (debug_file_directory) + 1
+ strlen (dir) + i
+ strlen (DEBUG_SUBDIRECTORY) + strlen (DEBUG_SUBDIRECTORY)
+ strlen ("/") + strlen ("/")
+ strlen (basename) + strlen (basename)
@ -1403,6 +1409,7 @@ find_separate_debug_file (struct objfile *objfile)
{ {
xfree (basename); xfree (basename);
xfree (dir); xfree (dir);
xfree (canon_name);
return xstrdup (debugfile); return xstrdup (debugfile);
} }
@ -1416,6 +1423,7 @@ find_separate_debug_file (struct objfile *objfile)
{ {
xfree (basename); xfree (basename);
xfree (dir); xfree (dir);
xfree (canon_name);
return xstrdup (debugfile); return xstrdup (debugfile);
} }
@ -1429,12 +1437,12 @@ find_separate_debug_file (struct objfile *objfile)
{ {
xfree (basename); xfree (basename);
xfree (dir); xfree (dir);
xfree (canon_name);
return xstrdup (debugfile); return xstrdup (debugfile);
} }
/* If the file is in the sysroot, try using its base path in the /* If the file is in the sysroot, try using its base path in the
global debugfile directory. */ global debugfile directory. */
canon_name = lrealpath (dir);
if (canon_name if (canon_name
&& strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0 && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
&& IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)])) && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
@ -1449,6 +1457,7 @@ find_separate_debug_file (struct objfile *objfile)
xfree (canon_name); xfree (canon_name);
xfree (basename); xfree (basename);
xfree (dir); xfree (dir);
xfree (canon_name);
return xstrdup (debugfile); return xstrdup (debugfile);
} }
} }