NetBSD Problem Report #44183
From www@NetBSD.org Wed Dec 1 23:14:47 2010
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by www.NetBSD.org (Postfix) with ESMTP id 3191863BA9C
for <gnats-bugs@gnats.NetBSD.org>; Wed, 1 Dec 2010 23:14:47 +0000 (UTC)
Message-Id: <20101201231447.11EA263B95F@www.NetBSD.org>
Date: Wed, 1 Dec 2010 23:14:47 +0000 (UTC)
From: ac3.87.z@gmail.com
Reply-To: ac3.87.z@gmail.com
To: gnats-bugs@NetBSD.org
Subject: Shell file name completion aborts shell process or prints wrong data.
X-Send-Pr-Version: www-1.0
>Number: 44183
>Category: lib
>Synopsis: Shell file name completion aborts shell process or prints wrong data.
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: dholland
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Dec 01 23:15:00 +0000 2010
>Closed-Date: Thu Dec 02 04:43:38 +0000 2010
>Last-Modified: Mon Dec 06 00:10:06 +0000 2010
>Originator: Sergio Acereda
>Release: -current
>Organization:
>Environment:
NetBSD new-host-4 5.99.40 NetBSD 5.99.40 (DM) #0: Sun Nov 21 21:37:10 CET 2010 root@.:/usr/obj/sys/arch/amd64/compile/DM amd64
>Description:
Shell file name completion aborts shell process or prints wrong data.
>How-To-Repeat:
- Login with /bin/sh
- Try TAB file completion with some directories (/usr/bin, /var/tmp...).
- The shell will crash or print null/wrong entries.
>Fix:
Index: lib/libedit/filecomplete.c
===================================================================
RCS file: /cvsroot/src/lib/libedit/filecomplete.c,v
retrieving revision 1.20
diff -u -r1.20 filecomplete.c
--- lib/libedit/filecomplete.c 15 Nov 2010 21:24:31 -0000 1.20
+++ lib/libedit/filecomplete.c 1 Dec 2010 22:56:21 -0000
@@ -59,7 +59,7 @@
#include "histedit.h"
#include "filecomplete.h"
-static Char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@',
+static const Char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@',
'$', '>', '<', '=', ';', '|', '&', '{', '(', '\0' };
@@ -341,10 +341,10 @@
* 'matches' is list of strings, 'len' is number of strings in 'matches',
* 'max' is maximum length of string in 'matches'.
*/
-void
-fn_display_match_list (EditLine *el, char **matches, size_t len, size_t max)
+static void
+_fn_display_match_list (EditLine *el, char **matches, size_t len, size_t max)
{
- size_t i, idx, limit, count;
+ size_t i, limit;
int screenwidth = el->el_term.t_size.h;
/*
@@ -355,25 +355,21 @@
if (limit == 0)
limit = 1;
- /* how many lines of output */
- count = len / limit;
- if (count * limit < len)
- count++;
-
/* Sort the items if they are not already sorted. */
- qsort(&matches[1], (size_t)(len - 1), sizeof(char *),
- _fn_qsort_string_compare);
+ qsort(matches, len, sizeof(char *), _fn_qsort_string_compare);
- idx = 1;
- for(; count > 0; count--) {
- int more = limit > 0 && matches[0];
- for(i = 0; more; i++, idx++) {
- more = i < limit && matches[idx + 1];
- (void)fprintf(el->el_outfile, "%-*s%s", (int)max,
- matches[idx], more ? " " : "");
- }
- (void)fprintf(el->el_outfile, "\n");
- }
+ for (i = 0; i < len; i++)
+ fprintf(el->el_outfile, "%-*s%s",
+ (int)max,
+ matches[i],
+ i == (len-1) || (i % limit) == limit-1? "\n" : " ");
+}
+
+void
+fn_display_match_list (EditLine *el, char **matches, size_t len, size_t max)
+{
+ /* Don't process the first argument */
+ _fn_display_match_list(el, matches + 1, len - 1, max);
}
/*
@@ -492,7 +488,7 @@
if (match_len > maxlen)
maxlen = match_len;
}
- matches_num = i - 1;
+ matches_num = i;
/* newline to get on next line from command line */
(void)fprintf(el->el_outfile, "\n");
@@ -504,7 +500,7 @@
if (matches_num > query_items) {
(void)fprintf(el->el_outfile,
"Display all %zu possibilities? (y or n) ",
- matches_num);
+ matches_num-1);
(void)fflush(el->el_outfile);
if (getc(stdin) != 'y')
match_display = 0;
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: lib-bug-people->dholland
Responsible-Changed-By: dholland@NetBSD.org
Responsible-Changed-When: Thu, 02 Dec 2010 04:12:48 +0000
Responsible-Changed-Why:
take
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/44183 CVS commit: src/lib/libedit
Date: Thu, 2 Dec 2010 04:35:17 +0000
Module Name: src
Committed By: dholland
Date: Thu Dec 2 04:35:17 UTC 2010
Modified Files:
src/lib/libedit: filecomplete.c
Log Message:
Fix up bodgy code for printing completion matches; it used to sometimes
skip entries, print (null), run off the end of the array, or occasionally
receive SIGSEGV, and now will, hopefully at least, do none of that.
Based in part on the patch in PR 44183 from Sergio Acereda; I also
did some tidyup and fixed it to print top-to-bottom first like ls(1).
To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 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->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Thu, 02 Dec 2010 04:43:38 +0000
State-Changed-Why:
fixed, thanks.
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/44183 CVS commit: src/lib/libedit
Date: Thu, 2 Dec 2010 04:42:46 +0000
Module Name: src
Committed By: dholland
Date: Thu Dec 2 04:42:46 UTC 2010
Modified Files:
src/lib/libedit: filecomplete.c
Log Message:
add const, from PR 44183.
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libedit/filecomplete.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/44183 CVS commit: src/lib/libedit
Date: Mon, 6 Dec 2010 00:05:39 +0000
Module Name: src
Committed By: dholland
Date: Mon Dec 6 00:05:39 UTC 2010
Modified Files:
src/lib/libedit: filecomplete.c
Log Message:
Improve previous to avoid changing the interface of an externally
exposed function. (But note that this function is neither documented
nor declared in any installed header file, and it probably should not
be externally exposed.) Related to PR 44183, closes PR 44186.
To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libedit/filecomplete.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.