Received: from list by lists.gnu.org with archive (Exim 4.71) id 1U7q0Y-0001ej-Pt for mharc-grub-devel@gnu.org; Tue, 19 Feb 2013 11:25:30 -0500 Received: from eggs.gnu.org ([208.118.235.92]:43666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7q0S-0001d0-4f for grub-devel@gnu.org; Tue, 19 Feb 2013 11:25:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U7q0K-0006hB-Uz for grub-devel@gnu.org; Tue, 19 Feb 2013 11:25:24 -0500 Received: from mail-la0-x235.google.com ([2a00:1450:4010:c03::235]:40262) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7q0J-0006dU-VV for grub-devel@gnu.org; Tue, 19 Feb 2013 11:25:16 -0500 Received: by mail-la0-f53.google.com with SMTP id fr10so6578354lab.26 for ; Tue, 19 Feb 2013 08:25:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:subject:date:message-id:x-mailer; bh=uyQ+PWC5GNyy4yR6L2KQ9AGaK2SI7l2BZXrs1cI5Qow=; b=rKt/DotncW9WJNrGYMc6+kHT6WPkOm7oC0OlTRq8ZZtcD+41y+z6470icmNx1bm/lo K09Df2xhhWdeaYfVciRzzDTUyomFxNGnoeEm8TLHRoiZGkpXJtzklsQGGv4jNGiMYsha z+sKFQkNmuYGGoe6pSzCzVRRABL5jZDZcLli55dbyegxXj4qIJmPbI/v2pHXOHUZQD/v qrtGhLk+t4LNjIzez+NJMoWOEni2jPENtzHaXuyPvXlicxMwhtkHvNYiSOftcwzxwIM0 sEXoc3+1ybIriSLd3IFXnEYbuBwZFsX8WVywZ2YfWe6M4T0TnpMGBxU0FXkMm3fylW7R K9qA== X-Received: by 10.112.41.101 with SMTP id e5mr7206592lbl.120.1361291111323; Tue, 19 Feb 2013 08:25:11 -0800 (PST) Received: from localhost.localdomain (ppp91-78-198-46.pppoe.mtu-net.ru. [91.78.198.46]) by mx.google.com with ESMTPS id tm10sm37402760lab.10.2013.02.19.08.25.10 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Feb 2013 08:25:10 -0800 (PST) From: Andrey Borzenkov To: grub-devel@gnu.org Subject: [PATCH] Fix unallocated memory access in insert_string Date: Tue, 19 Feb 2013 20:23:52 +0400 Message-Id: <1361291032-15157-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::235 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2013 16:25:30 -0000 When appending string at the end, there is nothing to shift down and (screen->line + 2) points beyond allocated array. Signed-off-by: Andrey Borzenkov --- ChangeLog | 5 +++++ grub-core/normal/menu_entry.c | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 654ebcb..2be5967 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-02-19 Andrey Borzenkov + + * grub-core/normal/menu_entry.c (insert_string): fix off by one + access to unallocated memory. + 2013-02-19 Paulo Flabiano Smorigo Support Openfirmware disks with non-512B sectors. diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index 7cd67f3..85f97da 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -393,11 +393,12 @@ insert_string (struct screen *screen, const char *s, int update) if (! screen->lines) return 0; - /* Scroll down. */ - grub_memmove (screen->lines + screen->line + 2, - screen->lines + screen->line + 1, - ((screen->num_lines - screen->line - 2) - * sizeof (struct line))); + /* Shift down if not appending after the last line. */ + if (screen->line < screen->num_lines - 2) + grub_memmove (screen->lines + screen->line + 2, + screen->lines + screen->line + 1, + ((screen->num_lines - screen->line - 2) + * sizeof (struct line))); if (! init_line (screen, screen->lines + screen->line + 1)) return 0; -- tg: (cc35b49..) fu/insert_string-unallocated-memory (depends on: master)