Readline library crash on custom completion
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
readline5 (Ubuntu) |
Triaged
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: libreadline5
Description
=======
Using up-to-date feisty.
I am using libreadline to provide custom completion for an application.
Using custom completion involves setting a global C symbol
(rl_attempted_
of suitable matches:
char ** match_generator
The char ** result ends with a (char *)NULL. If no matches are found, this
returns the NULL on the first position which confuses readline (see patch).
Steps to reproduce:
============
/* compile: gcc -Wall -O -o rltest rltest.c -lreadline */
#include <stdlib.h>
#include <readline/
#include <readline/
char ** match_func(const char * text, int start, int end)
{
char ** ret = (char **)malloc(
ret[0] = 0;
return ret;
}
int main()
{
return 0;
}
Fixes
====
Existing applications can simply do "if !matches[0] then matches=0".
To get expected (IMHO) behaviour from the library:
--- readline-
+++ readline-
@@ -961,6 +961,7 @@
if (rl_attempted_
{
matches = (*rl_attempted_
+ if (matches && ! matches[0]) matches = 0;
if (matches || rl_attempted_
{
====
Cheers!
Actually 'matches' should also be free()'d.
Attached patch for this.