NetBSD Problem Report #57016

From www@netbsd.org  Tue Sep 20 22:59:41 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_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 669F11A9239
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 20 Sep 2022 22:59:41 +0000 (UTC)
Message-Id: <20220920225940.3EE931A923A@mollari.NetBSD.org>
Date: Tue, 20 Sep 2022 22:59:40 +0000 (UTC)
From: ricky@rzhou.org
Reply-To: ricky@rzhou.org
To: gnats-bugs@NetBSD.org
Subject: libedit no longer supports multi-line history
X-Send-Pr-Version: www-1.0

>Number:         57016
>Category:       lib
>Synopsis:       libedit no longer supports multi-line history
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 20 23:00:01 +0000 2022
>Last-Modified:  Wed Sep 21 01:35:01 +0000 2022
>Originator:     Ricky Zhou
>Release:        N/A
>Organization:
>Environment:
N/A
>Description:
Some applications take multi-line commands, so they may call readline() multiple times and then call add_history() on a multi-line command.

Handling of multiline history was broken in https://github.com/NetBSD/src/commit/a90574952794b3edab8563128abe32af6ba66a4c#diff-1d1f44076d0edc654db369bcf936482e9d7938c541dad2a84cee3eea2f9f7608L468-L470

Specifically, the code:

lastidx = count - 1;
if (buf[lastidx] == '\n')
    buf[lastidx] = '\0';

was replaced with:

buf[strcspn(buf, "\n")] = '\0';

The new code cuts the string at the first newline rather than trimming off the last newline.

Thanks to Ethan Wei for identifying this issue!
>How-To-Repeat:
Call add_history/history on a multi-line string, then call readline/el_gets. Press up, enter. After pressing up, the multi-line command is displayed, but after pressing enter, only the first line is returned.
>Fix:
Could the problematic piece of the patch be reverted? Not sure if the behavior change was intentional.

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57016 CVS commit: src/lib/libedit
Date: Tue, 20 Sep 2022 19:41:14 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Tue Sep 20 23:41:14 UTC 2022

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

 Log Message:
 PR/57016: Ricky Zhou: Revert to trimming the last newline instead of the
 first one so that multi-line commands work again.


 To generate a diff of this commit:
 cvs rdiff -u -r1.174 -r1.175 src/lib/libedit/readline.c

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

From: Ricky Zhou <ricky@rzhou.org>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: PR/57016 CVS commit: src/lib/libedit
Date: Tue, 20 Sep 2022 17:56:12 -0700

 Thank you for responding so quickly!

 I was looking through the patch at
 http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit/readline.c?rev=1.175&content-type=text/x-cvsweb-markup&only_with_tag=MAIN
 - does the declaration of lastidx need to be added back as well?

 Thanks,
 Ricky

 On Tue, Sep 20, 2022 at 4:45 PM Christos Zoulas <christos@netbsd.org> wrote:
 >
 > The following reply was made to PR lib/57016; it has been noted by GNATS.
 >
 > From: "Christos Zoulas" <christos@netbsd.org>
 > To: gnats-bugs@gnats.NetBSD.org
 > Cc:
 > Subject: PR/57016 CVS commit: src/lib/libedit
 > Date: Tue, 20 Sep 2022 19:41:14 -0400
 >
 >  Module Name:   src
 >  Committed By:  christos
 >  Date:          Tue Sep 20 23:41:14 UTC 2022
 >
 >  Modified Files:
 >         src/lib/libedit: readline.c
 >
 >  Log Message:
 >  PR/57016: Ricky Zhou: Revert to trimming the last newline instead of the
 >  first one so that multi-line commands work again.
 >
 >
 >  To generate a diff of this commit:
 >  cvs rdiff -u -r1.174 -r1.175 src/lib/libedit/readline.c
 >
 >  Please note that diffs are not public domain; they are subject to the
 >  copyright notices on the relevant files.
 >

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57016 CVS commit: src/lib/libedit
Date: Tue, 20 Sep 2022 21:33:53 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Wed Sep 21 01:33:53 UTC 2022

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

 Log Message:
 PR/57016: Ricky Zhou: declare lastidx


 To generate a diff of this commit:
 cvs rdiff -u -r1.175 -r1.176 src/lib/libedit/readline.c

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

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2022 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.