From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=DKIM_ADSP_ALL,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=no autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id f68a2aee for ; Mon, 27 May 2019 23:34:28 +0000 (UTC) Received: (qmail 19801 invoked by alias); 27 May 2019 23:34:14 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44372 Received: (qmail 29255 invoked by uid 1010); 27 May 2019 23:34:13 -0000 X-Qmail-Scanner-Diagnostics: from mx.spodhuis.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25461. spamassassin: 3.4.2. Clear:RC:0(94.142.241.89):SA:0(-4.3/5.0):. Processed in 1.480582 secs); 27 May 2019 23:34:13 -0000 X-Envelope-From: zsh-workers+phil.pennock@spodhuis.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at spodhuis.org designates 94.142.241.89 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d201905; h=Content-Type:MIME-Version:Message-ID:Subject:To: From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=i2WylP5/zjkCxFu6zWNbhZdhut+hns26nvwogDqbCEw=; b=tGv9ku1gltUkODW/TzO8VuYMGL l0bG5ebJxUBJoqwKIokpw/FmbA1J68QbnVTCuJjl8jhqiJGvi67dUdS/wY6PN8VgBT0a7cBmHKDVq 17vLp11PsIWYr00iCYjoyJy1JR0RGWCOTCmgDNSCp8oIPv3v7ZgvlC0w8NHpy9Lwy6tpTXBGtqr6x 6GSPDaY/AlKnP4ulxjVnsGXt3yUHgNHVagDFL/hdKWoWw34tHHib2KjK/xNOpZfiBMRv9u7ZyDspi 5LhfQQDZGMMIEZYGlt3TGjV/vGSdnAP5lvCIWSxwHnLQxORLrvVj/bqa3drs+xDkgBK96NegE7sAv 5E0Fz/mw==; DKIM-Signature: v=1; a=ed25519-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d201905e2; h=Content-Type:MIME-Version:Message-ID:Subject: To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=i2WylP5/zjkCxFu6zWNbhZdhut+hns26nvwogDqbCEw=; b=FuWzUEWWtcuiqXxzB2LkxOJZRt T54pA0zZSnfkWA5jahz/YoImHW0HPgPlN0QLIhByNalZTVpK/UjJ4JgiCoBg==; Date: Mon, 27 May 2019 19:33:32 -0400 From: Phil Pennock To: zsh-workers@zsh.org Subject: [PATCH] _ssh_hosts: abort early if in a path Message-ID: <20190527233331.GA84827@phil-pennock> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline OpenPGP: url=https://www.security.spodhuis.org/PGP/keys/0x4D1E900E14C1CC04.asc The SSH hosts completion is often used in a context where a host or a file is being matched; with host completion happening first, there can be a lot of work parsing complex SSH configs and thus that can be slow. Assuming that for the purposes of SSH, no hostname starts `./` or `/`, abort early on trying to complete a hostname which starts with one of those. UNC paths shouldn't be an issue for SSH, I don't _think_. --- Completion/Unix/Type/_ssh_hosts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Completion/Unix/Type/_ssh_hosts b/Completion/Unix/Type/_ssh_hosts index e20142cfd..7e40f3fa7 100644 --- a/Completion/Unix/Type/_ssh_hosts +++ b/Completion/Unix/Type/_ssh_hosts @@ -4,6 +4,15 @@ local -a config_hosts local config integer ind +# If it looks like a path, it's not a host for our purposes, abort early so +# that combined path+host matching can more efficiently deal with local +# paths. +case "$PREFIX" in + ( /* | ./* ) + return + ;; +esac + # If users-hosts matches, we shouldn't complete anything else. if [[ "$IPREFIX" == *@ ]]; then _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" && return -- 2.21.0