[syslinux] [PATCH 6/9] CLI: Fix command history traversal

Matt Fleming matt at console-pimps.org
Fri Nov 2 07:13:15 PDT 2012


From: Matt Fleming <matt.fleming at intel.com>

The up/down keys were broken with respect to traversing through the
command history because it was dereferencing a NULL pointer on the
first iteration.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>
---
 com32/elflink/ldlinux/cli.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c
index a1cf50c..65a5057 100644
--- a/com32/elflink/ldlinux/cli.c
+++ b/com32/elflink/ldlinux/cli.c
@@ -340,9 +340,16 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
 	case KEY_UP:
 	    {
 		if (!list_empty(&cli_history_head)) {
+		    struct list_head *next;
+
+		    if (!comm_counter)
+			next = cli_history_head.next;
+		    else
+			next = comm_counter->list.next;
+
 		    comm_counter =
-			list_entry(comm_counter->list.next,
-				   typeof(*comm_counter), list);
+			list_entry(next, typeof(*comm_counter), list);
+
 		    if (&comm_counter->list == &cli_history_head) {
 			strcpy(cmdline, temp_cmdline);
 		    } else {
@@ -357,9 +364,16 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
 	case KEY_DOWN:
 	    {
 		if (!list_empty(&cli_history_head)) {
+		    struct list_head *prev;
+
+		    if (!comm_counter)
+			prev = cli_history_head.prev;
+		    else
+			prev = comm_counter->list.prev;
+
 		    comm_counter =
-			list_entry(comm_counter->list.prev,
-				   typeof(*comm_counter), list);
+			list_entry(prev, typeof(*comm_counter), list);
+
 		    if (&comm_counter->list == &cli_history_head) {
 			strcpy(cmdline, temp_cmdline);
 		    } else {
-- 
1.7.11.7




More information about the Syslinux mailing list