All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollis@penguinppc.org>
To: grub-devel@gnu.org
Subject: strndup broken
Date: Sat, 8 Jan 2005 17:48:20 -0600	[thread overview]
Message-ID: <20050108234820.GA7198@miracle> (raw)

A while back I made the unpleasent discovery that grub_strndup was
broken. This patch fixes it, but the author has been having trouble
sending it out.

-Hollis

2005-01-08  Ian Abel  <iga20@cam.ac.uk>

	* kern/misc.c (grub_strndup): Don't call grub_strlen.
	Null-terminate the new string if possible.

Index: kern/misc.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/misc.c,v
retrieving revision 1.15
diff -u -p -r1.15 misc.c
--- kern/misc.c	14 Sep 2004 08:56:51 -0000	1.15
+++ kern/misc.c	8 Jan 2005 23:47:55 -0000
@@ -341,16 +341,21 @@ grub_strndup (const char *s, grub_size_t
 {
   grub_size_t len = 0;
   char *p = (char *) s;
-  
+
   while (*(p++) && len < n)
     len++;
 
-  len = grub_strlen (s) + 1;
+  if (*p)
+    len++;
+
   p = (char *) grub_malloc (len);
   if (! p)
     return 0;
 
-  return grub_memcpy (p, s, len);
+  if (n < len)
+    p[n] = '\0';
+
+  return grub_memcpy (p, s, n);
 }
 
 void *



             reply	other threads:[~2005-01-09  0:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-08 23:48 Hollis Blanchard [this message]
2005-01-21 20:19 ` strndup broken Marco Gerards
2005-01-22  5:38   ` Hollis Blanchard
2005-01-22 13:46     ` Marco Gerards

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=20050108234820.GA7198@miracle \
    --to=hollis@penguinppc.org \
    --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.