Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>
Cc: gdb-patches@sourceware.org, rustyBSD@gmx.fr
Subject: Re: [PATCH] Fix readlink calls in GDB
Date: Mon, 26 Nov 2012 16:12:00 -0000	[thread overview]
Message-ID: <50B38E82.1020102@redhat.com> (raw)
In-Reply-To: <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


  reply	other threads:[~2012-11-26 16:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-26 14:20 Pedro Alves
2012-11-26 14:43 ` Pierre Muller
2012-11-26 15:16   ` Pedro Alves
2012-11-26 15:31     ` Pierre Muller
2012-11-26 16:12       ` Pedro Alves [this message]
2012-11-26 16:33         ` Pierre Muller
2012-11-26 16:54           ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50B38E82.1020102@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pierre.muller@ics-cnrs.unistra.fr \
    --cc=rustyBSD@gmx.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox