bug-bash
[Top][All Lists]
Advanced

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

'=', '[', ']' in history_word_delimiters causes infinite loop


From: Hiroo Hayashi
Subject: '=', '[', ']' in history_word_delimiters causes infinite loop
Date: Wed, 28 Jan 2004 01:32:40 -0600

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: cygwin
Compiler: i686-pc-cygwin-gcc
Compilation CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' -DCONF_VENDOR='pc' 
-DSHELL -DHAVE_CONFIG_H -DRECYCLES_PIDS  -I.  
-I/home/RLandheer/cygwin-contrib/bash/bash-2.05b 
-I/home/RLandheer/cygwin-contrib/bash/bash-2.05b/include 
-I/home/RLandheer/cygwin-contrib/bash/bash-2.05b/lib  -O2
uname output: CYGWIN_NT-5.1 herbie 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 
unknown unknown Cygwin
Machine Type: i686-pc-cygwin

Both readline-4.3 and readline-5.0-alpha have this problem.

Description:

When one of some charactors is in history_word_delimiters,
history_expand goes into infinite loop when expanding a line which
include the charactor.

Repeat-By:

The first history_expand call returns but the second one does not.
------------------------------------------------------------------------
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>

main()
{
  char *output;
  int ret;
  
  /* initialize */
  using_history();

  add_history("abc=xyz");
  history_word_delimiters = " \t\n";

  ret = history_expand("!$", &output); /* returns */
  printf("%d:%s\n", ret, output);
  xfree(output);

  history_word_delimiters = " \t\n=";
  ret = history_expand("!$", &output); /* never returns */
  printf("%d:%s\n", ret, output);
  xfree(output);

  exit (0);
}
------------------------------------------------------------------------

Here is a simple example.  history_tokenize() which is called by
history_expand() goes into a infinite loop.

------------------------------------------------------------------------
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>

main()
{
  char *output;
  int ret;
  
  /* initialize */
  using_history();

  history_word_delimiters = " \t\n=";
  history_tokenize("a=x"); /* never returns */
  printf("done\n");
  exit(0);
}
------------------------------------------------------------------------

Fix:

I don't understand the code well.  How about the following patch?
This is the patch for readline-5.0-alpha.

--- histexpand.c.org    2004-01-28 02:04:40.643579200 -0500
+++ histexpand.c        2004-01-28 02:04:04.451537600 -0500
@@ -1445,6 +1445,12 @@
        }
     }
 
+  if (member (string[i], history_word_delimiters))
+    {
+      i++;
+      return i;
+    }
+
   /* Get word from string + i; */
 
   if (member (string[i], HISTORY_QUOTE_CHARACTERS))

-- 
Hiroo Hayashi





reply via email to

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