a5bd9f6
From c6faf0e2eb58a0f9d31c6b110cd58b4956b13465 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Andrey Borzenkov <arvidjaar@gmail.com>
a5bd9f6
Date: Mon, 25 Feb 2013 22:42:25 +0100
a5bd9f6
Subject: [PATCH 157/364] 	* grub-core/normal/menu_entry.c
a5bd9f6
 (insert_string): fix off by one 	access to unallocated memory.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog                     |  5 +++++
a5bd9f6
 grub-core/normal/menu_entry.c | 11 ++++++-----
a5bd9f6
 2 files changed, 11 insertions(+), 5 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 107c049..cc5d5e3 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,5 +1,10 @@
a5bd9f6
 2013-02-25  Andrey Borzenkov <arvidjaar@gmail.com>
a5bd9f6
 
a5bd9f6
+	* grub-core/normal/menu_entry.c (insert_string): fix off by one
a5bd9f6
+	access to unallocated memory.
a5bd9f6
+
a5bd9f6
+2013-02-25  Andrey Borzenkov <arvidjaar@gmail.com>
a5bd9f6
+
a5bd9f6
 	* Makefile.util.def: Add partmap/msdos.c to common library.
a5bd9f6
 	* include/grub/msdos_partition.h: Add GRUB_PC_PARTITION_TYPE_LDM
a5bd9f6
 	* grub-core/disk/ldm.c: Check for existence of
a5bd9f6
diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c
a5bd9f6
index 7cd67f3..85f97da 100644
a5bd9f6
--- a/grub-core/normal/menu_entry.c
a5bd9f6
+++ b/grub-core/normal/menu_entry.c
a5bd9f6
@@ -393,11 +393,12 @@ insert_string (struct screen *screen, const char *s, int update)
a5bd9f6
 	  if (! screen->lines)
a5bd9f6
 	    return 0;
a5bd9f6
 
a5bd9f6
-	  /* Scroll down. */
a5bd9f6
-	  grub_memmove (screen->lines + screen->line + 2,
a5bd9f6
-			screen->lines + screen->line + 1,
a5bd9f6
-			((screen->num_lines - screen->line - 2)
a5bd9f6
-			 * sizeof (struct line)));
a5bd9f6
+	  /* Shift down if not appending after the last line. */
a5bd9f6
+	  if (screen->line < screen->num_lines - 2)
a5bd9f6
+	    grub_memmove (screen->lines + screen->line + 2,
a5bd9f6
+			  screen->lines + screen->line + 1,
a5bd9f6
+			  ((screen->num_lines - screen->line - 2)
a5bd9f6
+			   * sizeof (struct line)));
a5bd9f6
 
a5bd9f6
 	  if (! init_line (screen, screen->lines + screen->line + 1))
a5bd9f6
 	    return 0;
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6