This is the mail archive of the
gdb-prs@sources.redhat.com
mailing list for the GDB project.
Re: gdb/417: GDB crashes when source path has few links
- From: "Michael Veksler" <VEKSLER at il dot ibm dot com>
- To: nobody at sources dot redhat dot com
- Cc: gdb-prs at sources dot redhat dot com,
- Date: 17 Mar 2002 08:38:00 -0000
- Subject: Re: gdb/417: GDB crashes when source path has few links
- Reply-to: "Michael Veksler" <VEKSLER at il dot ibm dot com>
The following reply was made to PR gdb/417; it has been noted by GNATS.
From: "Michael Veksler" <VEKSLER@il.ibm.com>
To: Andrew Cagney <ac131313@cygnus.com>
Cc: gdb-gnats@sources.redhat.com
Subject: Re: gdb/417: GDB crashes when source path has few links
Date: Sun, 17 Mar 2002 10:29:49 +0200
Andrew wrote:
> >(ulgh, two different bug reports against the same 3 line patch :-).
Which one? I scanned the database, and could not find any similar bug.
I worte (Michael Veksler):
> > Sometimes gdb crashes when it tries to display sources.
> >
> > open_source_file() calls openp() which assumes that if open() succeeds
so
> > does canonicalize_file_name(). After openp() succeeded to open the
file,
> > open_source_file() assumes that it has a canonic file name. But this
> > assumption is incorrect.
>
> Does modifying utils.c to use realpath() instead of
> canonicalize_file_name() provide a tempoary work around to the problem?
> (I suspect not but might be worth a try).
My 3 lines patch fixes the problem:
--- gdb+dejagnu-5.1.90_20020313/gdb/utils.c.orig Thu Mar 14 10:06:02
2002
+++ gdb+dejagnu-5.1.90_20020313/gdb/utils.c Thu Mar 14 10:07:56 2002
@@ -2533,7 +2533,8 @@
gdb_realpath (const char *filename)
{
#ifdef HAVE_CANONICALIZE_FILE_NAME
- return canonicalize_file_name (filename);
+ char *canonic= canonicalize_file_name (filename);
+ return (canonic ? canonic : xstrdup(filename));
#elif defined (HAVE_REALPATH)
#if defined (PATH_MAX)
char buf[PATH_MAX];
It simply performs the same check that the call to realpath does. If the
result
is NULL, then return the original filename. Probably, if you will undef
HAVE_CANONICALIZE_FILE_NAME, then everything will work fine, because the
call
realpath implements the check for NULL.
> (NB: need to also check that canonicalize_file_name() allocates space
> from the heap.)
It does.
You can look at:
1. Documentation:
http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_269.html
2. Source:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/~checkout~/libc/stdlib/canonicalize.c?rev=1.19&content-type=text/plain&cvsroot=glibc
realpath() is implemented by the same code as canonicalize_file_name() is.
Except for malloc()-ing the string buffer they are the same function.
Allocation is performed by:
#ifdef PATH_MAX
path_max = PATH_MAX;
#else
path_max = pathconf (name, _PC_PATH_MAX);
if (path_max <= 0)
path_max = 1024;
#endif
malloc (path_max)