[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash-4.1.5 crashes when trying to edit multiline command in vi mode

From: Roman Rakus
Subject: bash-4.1.5 crashes when trying to edit multiline command in vi mode
Date: Thu, 15 Apr 2010 15:51:50 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20100330 Fedora/3.0.4-1.fc11 Lightning/1.0b2pre Thunderbird/3.0.4

In bash-4.1 patchlevel 5 (probably all older versions) crashes.

1. set -o vi  #set ups vi command line editing
2. type the following command as seen, but do not hit enter at last one
for i in `ls`
echo $i
3.After typeing done (but not enter), hit escape
4.type the letter v to open a vi editor to edit command above (for i ...)

Following patch do 2 thing.
1) check if hlist[i] isn't NULL
2) Don't invoke vi editing if command is multilined

ad 2) I didn't find any specification what should shell do with multiline command. But editing multiline can make troubles. Anyway: Should be editing multilined command allowed? If so, should it edit all lines or only current line?

ad 1) It's just poor check and can return NULL. Maybe it can be checked elsewhere. And problem is in counting the end of history. In file builtins/fc.def on line 304 you are subtracting `hist_last_line_added'. `hist_last_line_added' is 0 but the last is added - in edit_and_execute_command function. Maybe setting `hist_last_line_added' to 1 in that function can somehow help.

diff -up bash-4.1/bashline.c.check bash-4.1/bashline.c
--- bash-4.1/bashline.c.check    2010-04-14 14:05:06.000000000 +0200
+++ bash-4.1/bashline.c    2010-04-14 14:07:07.000000000 +0200
@@ -867,6 +867,12 @@ edit_and_execute_command (count, c, edit
   rrs = rl_readline_state;
   cclc = current_command_line_count;

+  if (cclc > 0)
+    {
+      /* Don't edit multiline command*/
+      return 1;
+    }
   /* Accept the current line. */
   rl_newline (1, c);

diff -up bash-4.1/builtins/fc.def.check bash-4.1/builtins/fc.def
--- bash-4.1/builtins/fc.def.check    2010-04-14 13:20:28.000000000 +0200
+++ bash-4.1/builtins/fc.def    2010-04-14 13:22:08.000000000 +0200
@@ -131,8 +131,8 @@ typedef struct repl {
 } REPL;

 /* Accessors for HIST_ENTRY lists that are called HLIST. */
-#define histline(i) (hlist[(i)]->line)
-#define histdata(i) (hlist[(i)]->data)
+#define histline(i) (hlist[(i)] ? hlist[(i)]->line : NULL)
+#define histdata(i) (hlist[(i)] ? hlist[(i)]->data : NULL)

 #define FREE_RLIST() \
     do { \


reply via email to

[Prev in Thread] Current Thread [Next in Thread]