NetBSD Problem Report #50863

From  Sat Feb 27 17:24:08 2016
Return-Path: <>
Received: from ( [])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "", Issuer "Postmaster" (verified OK))
	by (Postfix) with ESMTPS id A9E0B7ABE4
	for <>; Sat, 27 Feb 2016 17:24:08 +0000 (UTC)
Message-Id: <>
Date: Sat, 27 Feb 2016 17:24:07 +0000 (UTC)
Subject: libedit el_end() messes up term settings if piped
X-Send-Pr-Version: www-1.0

>Number:         50863
>Category:       lib
>Synopsis:       libedit el_end() messes up term settings if piped
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 27 17:25:00 +0000 2016
>Closed-Date:    Mon Feb 29 14:59:40 +0000 2016
>Last-Modified:  Mon Feb 29 14:59:40 +0000 2016
>Originator:     John Hein
>Release:        head
Noticed with freebsd ports version of libedit (basically 201503 netbsd version).  Reproduced with libedit code from netbsd head on freebsd.

FreeBSD 9.3-STABLE-20150728 FreeBSD 9.3-STABLE-20150728 #8: Fri Jul 31 09:01:31 MDT 2015  i386

Sorry I don't have a netbsd box to use at the moment.  But it's easy to confirm if you do.  And code inspection of head netbsd code seems to show the problem still exists.
% cat foo.c
#include <stdio.h>
#include <histedit.h>

static EditLine *el_e = 0;

main(int argc, char **argv)
        el_e = el_init("foo", stdin, stdout, stderr);
        if (el_e)
                printf("el_init failed\n");
        return 0;

cc foo.c -ledit -o foo && ./foo | cat

The output after el_end() has stair stepped lines (no CR), 'stty -a' shows the baud rate at 50, and on freebsd at least, that messes up things like vi and such.

Looking at the libedit code, it looks like there's a case where code in el_end() tries to restore the original tty settings.  But if the output is not a tty, the original tty settings were never saved.  So it restores invalid termios settings.

The problem is that tty_setup() checks if the output file descriptor is a tty and does a short circuit exit before the termios settings can be saved.  Then el_end(), unaware that the t_or struct is not correctly populated, happily restores the t_or settings that are bogus.
See description.
Record original termios settings in tty_setup() even if not isatty().  Or don't try to restore termios settings in tty_end() if tty_setup() never saved them (set a flag or use a pointer for t_or that's null unless the struct is valid or something like that).


From: "Christos Zoulas" <>
Subject: PR/50863 CVS commit: src/lib/libedit
Date: Sat, 27 Feb 2016 13:13:21 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sat Feb 27 18:13:21 UTC 2016

 Modified Files:
 	src/lib/libedit: tty.c tty.h

 Log Message:
 PR/50863: John Hein: libedit el_end() messes up term settings if piped
 Keep track if we initialized the tty, and only reset it if we did.

 To generate a diff of this commit:
 cvs rdiff -u -r1.57 -r1.58 src/lib/libedit/tty.c
 cvs rdiff -u -r1.18 -r1.19 src/lib/libedit/tty.h

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

State-Changed-From-To: open->closed
State-Changed-When: Mon, 29 Feb 2016 14:59:40 +0000
Christos fixed it, thanks!


NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD:,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.