All of lore.kernel.org
 help / color / mirror / Atom feed
From: Colin D Bennett <colin@gibibit.com>
To: grub-devel@gnu.org
Subject: Re: grub_strdup() error; or: grub_malloc() zeroes memory?
Date: Sat, 28 Jun 2008 08:35:26 -0700	[thread overview]
Message-ID: <20080628083526.239e5d5d@gibibit.com> (raw)
In-Reply-To: <486657CD.9000506@nic.fi>

[-- Attachment #1: Type: text/plain, Size: 808 bytes --]

On Sat, 28 Jun 2008 18:25:01 +0300
Vesa Jääskeläinen <chaac@nic.fi> wrote:

> Colin D Bennett wrote:
> > It looks like grub_strdup() does not terminate the returned string
> > with a 0 byte.  The only way I could see it working is if
> > grub_malloc() filled the returned memory with zeroes.  Does it?
> > 
> > From kern/misc.c: (circa line 476)
> > 
> >    char *
> >    grub_strdup (const char *s)
> >    {
> >      grub_size_t len;
> >      char *p;
> >      
> >      len = grub_strlen (s) + 1;
> >      p = (char *) grub_malloc (len);
> >      if (! p)
> >        return 0;
> > 
> >      return grub_memcpy (p, s, len);
> >    }
> 
> Zero is copied from source string... notice strlen() + 1.

Doh!
/me smacks his forehead.
Thanks for pointing that out.

Cheers,
Colin

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

      reply	other threads:[~2008-06-28 15:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-28 15:03 grub_strdup() error; or: grub_malloc() zeroes memory? Colin D Bennett
2008-06-28 15:25 ` Vesa Jääskeläinen
2008-06-28 15:35   ` Colin D Bennett [this message]

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=20080628083526.239e5d5d@gibibit.com \
    --to=colin@gibibit.com \
    --cc=grub-devel@gnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.