Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LtG2e-0006Nb-K1 for mharc-grub-devel@gnu.org; Mon, 13 Apr 2009 02:53:16 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LtG2d-0006MA-NR for grub-devel@gnu.org; Mon, 13 Apr 2009 02:53:15 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LtG2d-0006LS-87 for grub-devel@gnu.org; Mon, 13 Apr 2009 02:53:15 -0400 Received: from [199.232.76.173] (port=53393 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LtG2d-0006LJ-4J for grub-devel@gnu.org; Mon, 13 Apr 2009 02:53:15 -0400 Received: from mx20.gnu.org ([199.232.41.8]:15323) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LtG2c-0001h9-HJ for grub-devel@gnu.org; Mon, 13 Apr 2009 02:53:14 -0400 Received: from [74.93.104.97] (helo=sunset.davemloft.net) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LtG2b-00076z-RD for grub-devel@gnu.org; Mon, 13 Apr 2009 02:53:14 -0400 Received: from localhost (localhost [127.0.0.1]) by sunset.davemloft.net (Postfix) with ESMTP id A09FE35C4AC for ; Sun, 12 Apr 2009 23:53:04 -0700 (PDT) Date: Sun, 12 Apr 2009 23:53:04 -0700 (PDT) Message-Id: <20090412.235304.168196504.davem@davemloft.net> To: grub-devel@gnu.org From: David Miller X-Mailer: Mew version 6.2.51 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-detected-kernel: by mx20.gnu.org: Linux 2.6 (newer, 3) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Subject: [PATCH]: grub: Kill fixed device name length from make_device_name(). X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Apr 2009 06:53:15 -0000 make_device_name() uses an arbitrary value for the device name length, putting an arbitrary limit on such strings. We can do better by calculating the length of this string precisely. 2009-04-12 David S. Miller * util/hostdisk.c (make_device_name): Do not make any assumptions about the length of drive names. --- util/hostdisk.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/util/hostdisk.c b/util/hostdisk.c index 2ef2057..fd01a26 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -622,9 +622,15 @@ grub_util_biosdisk_fini (void) static char * make_device_name (int drive, int dos_part, int bsd_part) { + int len = strlen(map[drive].drive); char *p; - p = xmalloc (30); + if (dos_part >= 0) + len += 1 + ((dos_part + 1) / 10); + if (bsd_part >= 0) + len += 2; + + p = xmalloc (len); sprintf (p, "%s", map[drive].drive); if (dos_part >= 0) -- 1.6.2.3