mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Aring <alex.aring@gmail.com>
To: Teresa Gamez <t.gamez@phytec.de>
Cc: barebox@lists.infradead.org
Subject: Re: [BUG] readline history
Date: Thu, 28 Aug 2014 11:25:44 +0200	[thread overview]
Message-ID: <20140828092542.GA20889@omega> (raw)
In-Reply-To: <1409212205.4914.6.camel@lws-gamez.phytec.de>

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

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-08-28  9:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-28  7:50 Teresa Gamez
2014-08-28  8:35 ` Alexander Aring
2014-08-28  9:25 ` Alexander Aring [this message]
2014-08-28 10:08   ` Alexander Aring
2014-09-01  8:30 ` Sascha Hauer
2014-09-01  8:44   ` Alexander Aring
2014-09-01 12:25     ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140828092542.GA20889@omega \
    --to=alex.aring@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=t.gamez@phytec.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox