NetBSD Problem Report #54067

From www@netbsd.org  Wed Mar 20 05:02:09 2019
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 730C97A162
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 20 Mar 2019 05:02:09 +0000 (UTC)
Message-Id: <20190320050208.A434F7A1A3@mollari.NetBSD.org>
Date: Wed, 20 Mar 2019 05:02:08 +0000 (UTC)
From: apyhalov@gmail.com
Reply-To: apyhalov@gmail.com
To: gnats-bugs@NetBSD.org
Subject: libed
X-Send-Pr-Version: www-1.0

>Number:         54067
>Category:       lib
>Synopsis:       libed
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    abhinav
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 20 05:05:00 +0000 2019
>Closed-Date:    Mon Apr 01 06:33:06 +0000 2019
>Last-Modified:  Mon Apr 01 06:33:06 +0000 2019
>Originator:     Alexander Pyhalov
>Release:        
>Organization:
Southern Federal University
>Environment:
>Description:
https://github.com/NetBSD/src/commit/47081400d868e1d6dd5629bea97c599c48404839 has broken libedit compatibility to libreadline, which causes issues like incorrect completion in psql, when "space separated keywords" auto-complete as "space\ separated\ keywords". 
>How-To-Repeat:
The following program, linked with readline, autocomplete words as "Arthur Dent", "Ford Perfect" and so on. When linked with libedit, it autocomplete words as "Arthur\ Dent", "Ford\ Perfect" and so on.
(Note, this is checked with latest version of http://www.thrysoee.dk/editline/ on OpenIndiana, but issue is the same - rl_complete completes keywords as file names, which is incorrect.

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <readline/readline.h>
#include <readline/history.h>

char **character_name_completion(const char *, int, int);
char *character_name_generator(const char *, int);

char *character_names[] = {
    "Arthur Dent",
    "Ford Prefect",
    "Tricia McMillan",
    "Zaphod Beeblebrox",
    NULL
};

int main()
{
    rl_attempted_completion_function = character_name_completion;

    printf("Who's your favourite Hitchiker's Guide character?\n");
    char *buffer = readline("> ");
    if (buffer) {
        printf("You entered: %s\n", buffer);
        free(buffer);
    }

    return 0;
}

char **
character_name_completion(const char *text, int start, int end)
{
    rl_attempted_completion_over = 1;
    return rl_completion_matches(text, character_name_generator);
}

char *
character_name_generator(const char *text, int state)
{
    static int list_index, len;
    char *name;

    if (!state) {
        list_index = 0;
        len = strlen(text);
    }

    while ((name = character_names[list_index++])) {
        if (strncmp(name, text, len) == 0) {
            return strdup(name);
        }
    }

    return NULL;
}

>Fix:
So far, we are likely to revert this commit using the following patch:

--- libedit-20181209-3.1/src/filecomplete.c.~1~ 2018-05-25 21:09:38.000000000 +0000
+++ libedit-20181209-3.1/src/filecomplete.c     2019-03-20 07:48:13.111605101 +0000
@@ -650,15 +650,11 @@
                                 * it, unless we do filename completion and the
                                 * object is a directory. Also do necessary escape quoting
                                 */
-                               char *escaped_completion = escape_filename(el, matches[0]);
-                               if (escaped_completion == NULL)
-                                       goto out;
                                el_winsertstr(el,
-                                       ct_decode_string(escaped_completion, &el->el_scratch));
+                                       ct_decode_string(matches[0], &el->el_scratch));
                                el_winsertstr(el,
-                                               ct_decode_string((*app_func)(escaped_completion),
+                                               ct_decode_string((*app_func)(matches[0]),
                                                        &el->el_scratch));
-                               free(escaped_completion);
                        } else {
                                /*
                                 * Only replace the completed string with common part of

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: lib-bug-people->abhinav
Responsible-Changed-By: maya@NetBSD.org
Responsible-Changed-When: Wed, 20 Mar 2019 07:29:36 +0000
Responsible-Changed-Why:
ping committer


From: "Abhinav Upadhyay" <abhinav@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54067 CVS commit: src/lib/libedit
Date: Sun, 24 Mar 2019 16:42:49 +0000

 Module Name:	src
 Committed By:	abhinav
 Date:		Sun Mar 24 16:42:49 UTC 2019

 Modified Files:
 	src/lib/libedit: filecomplete.c

 Log Message:
 Only quote the completion matches if we are doing filename completion

 If the user supplies a value for the attempted_completion_function parameter
 then we cannot be sure if the completion is for filename or something else, in such
 a case don't attempt to quote the completion matches.

 Reviewed by christos

 This should address PR lib/54067


 To generate a diff of this commit:
 cvs rdiff -u -r1.51 -r1.52 src/lib/libedit/filecomplete.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->feedback
State-Changed-By: abhinav@NetBSD.org
State-Changed-When: Sun, 24 Mar 2019 16:54:45 +0000
State-Changed-Why:
iDoes this fix the problem?


From: Alexander Pyhalov <apyhalov@gmail.com>
To: gnats-bugs@netbsd.org
Cc: abhinav@netbsd.org, netbsd-bugs@netbsd.org, gnats-admin@netbsd.org
Subject: Re: lib/54067 (libed)
Date: Mon, 25 Mar 2019 07:33:54 +0300

 Yes.

 =D0=B2=D1=81, 24 =D0=BC=D0=B0=D1=80. 2019 =D0=B3. =D0=B2 19:54, <abhinav@ne=
 tbsd.org>:
 >
 > Synopsis: libed
 >
 > State-Changed-From-To: open->feedback
 > State-Changed-By: abhinav@NetBSD.org
 > State-Changed-When: Sun, 24 Mar 2019 16:54:45 +0000
 > State-Changed-Why:
 > iDoes this fix the problem?
 >
 >
 >


 --=20
 =D0=A1 =D1=83=D0=B2=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC,
 =D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80 =D0=9F=D1=8B=D1=85=
 =D0=B0=D0=BB=D0=BE=D0=B2

State-Changed-From-To: feedback->closed
State-Changed-By: abhinav@NetBSD.org
State-Changed-When: Mon, 01 Apr 2019 06:33:06 +0000
State-Changed-Why:
Submitter confirmed the fix. Thanks for the PR


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.