[BUG] readline history
Alexander Aring
alex.aring at gmail.com
Thu Aug 28 02:25:44 PDT 2014
Hi,
the issues is that hist_prev or hist_next runs:
"list_entry(history_current->next, struct history, list);"
on an empty list with no entries and history->line is a dangling pointer.
because the list head don't include a char *line and on an empty list
the attributes are prev == next.
I hacked a solution which check on an empty list at first and returning
NULL.
diff --git a/lib/readline.c b/lib/readline.c
index b70bca8..0892cf5 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -67,6 +67,9 @@ static const char *hist_prev(void)
{
struct history *history;
+ if (list_empty(&history_list))
+ return NULL;
+
if (history_current->prev == &history_list) {
history = list_entry(history_current, struct history, list);
getcmd_cbeep();
@@ -84,6 +87,9 @@ static const char *hist_next(void)
{
struct history *history;
+ if (list_empty(&history_list))
+ return NULL;
+
if (history_current->next == &history_list) {
history_current = &history_list;
return "";
@@ -301,6 +307,9 @@ int readline(const char *prompt, char *buf, int len)
else
hline = hist_next();
+ if (!hline)
+ break;
+
/* nuke the current line */
/* first, go home */
BEGINNING_OF_LINE();
Don't know if it should make a beep or not, just hacked not complete tested.
Maybe there are similar issues in other functions.
- Alex
More information about the barebox
mailing list