This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix readlink calls in GDB
- From: Pedro Alves <palves at redhat dot com>
- To: Pierre Muller <pierre dot muller at ics-cnrs dot unistra dot fr>
- Cc: gdb-patches at sourceware dot org, rustyBSD at gmx dot fr
- Date: Mon, 26 Nov 2012 15:45:06 +0000
- Subject: Re: [PATCH] Fix readlink calls in GDB
- References: <20121126142036.10142.97678.stgit@brno.lan> <004401cdcbe4$524136c0$f6c3a440$@muller@ics-cnrs.unistra.fr> <50B38790.5090206@redhat.com> <005301cdcbeb$1b177e50$51467af0$@muller@ics-cnrs.unistra.fr>
On 11/26/2012 03:31 PM, Pierre Muller wrote:
> I don't see any code setting the terminal char to '\0'
> in fbsd_pid_to_exec_file (fbsd-nat.c:40 rev 1.29)
char *
fbsd_pid_to_exec_file (int pid)
{
size_t len = MAXPATHLEN;
char *buf = xcalloc (len, sizeof (char));
^^^^^^^
char *path;
xcalloc memsets the memory to zero before returning. See man calloc.
> nor in linux_child_pid_to_exec_file (linux-nat.c:4311 rev 1.261)
static char *
linux_child_pid_to_exec_file (int pid)
{
char *name1, *name2;
name1 = xmalloc (MAXPATHLEN);
name2 = xmalloc (MAXPATHLEN);
make_cleanup (xfree, name1);
make_cleanup (xfree, name2);
memset (name2, 0, MAXPATHLEN);
^^^^^^
That memset clear the whole buffer, thus the buffer ends up
always nul-terminated.
> nor in nbsd_pid_to_exec_file (nbsd-nat.c:30 rev 1.10)...
That likewise uses xcalloc.
--
Pedro Alves