bug-readline
[Top][All Lists]
Advanced

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

[Bug-readline] readline discards input data when run with rl_event_hook


From: Yoann Guillot
Subject: [Bug-readline] readline discards input data when run with rl_event_hook
Date: Mon, 8 Sep 2008 18:53:35 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

Readline discards input data due to an off-by-one error on the ibuffer free 
size calculation.
This buffer is only used when the program defines the rl_event_hook callback.

To reproduce, run the following code:

***    sample    ***

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

int dummy(void) { return 0; }

int main(void)
{
        char *str;
        rl_event_hook = &dummy;
        str = readline("> ");
        printf("got '%s'\n", str);
        return 0;
}

// try to run  ruby -e 'puts "01"*513' | ./readtest

*** end of sample ***

this should display a 1026 character string, but the first 2*512 char are 
discarded.

You can also generate the same string, fire irb (the interactive ruby shell), 
and paste
it on the prompt: you'll notice that the characters at position 511 and 1022 
have
disappeared.

The following patch fixes these issues.

***    patch    ***

--- input.c.old 2008-09-08 18:12:04.000000000 +0200
+++ input.c     2008-09-08 18:13:27.000000000 +0200
@@ -134,7 +134,7 @@
 
   *key = ibuffer[pop_index++];
 
-  if (pop_index >= ibuffer_len)
+  if (pop_index > ibuffer_len)
     pop_index = 0;
 
   return (1);
@@ -373,7 +373,7 @@
       RL_SETSTATE (RL_STATE_INPUTPENDING);
     }
   ibuffer[push_index++] = key;
-  if (push_index >= ibuffer_len)
+  if (push_index > ibuffer_len)
     push_index = 0;
 
   return 1;

*** end of patch  ***

Bug seen and patched on the debian package for readline-5.2.2

-- 
Yoann Guillot




reply via email to

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