From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12598 invoked from network); 15 Dec 2021 23:57:44 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Dec 2021 23:57:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=45pn1QHgxViANGgslgaWFyhBVe/SvgDuw6l+VNyYC0U=; b=q/89RCgnct46l5azr/VCO2nUD8 1DT/+6bbSvvpiVeJrnol3l3Y1DVauAonDFzuuyxPfVP7I+jfRzZYgYCIhgXqkjzaoz1nbCESUv/YV 8/16KTZsCke32PFVT7qiaQXN4Z5afe0/0QD3Kl1z0dSKhc54XTRXlgCoSAg7IHnZgLS7LGFPrqhJx VESAmbhLkqzIpIgWWUdIV9/HaEBOIHjhI20ddS1PpDK2g4oL4HifB+BVuQcBNTzdeOoCAN/9JpBZN v5Da2Cgp57r8pgDNrg29rEZRhA1azhmpXdz2rFor0HtTrg2kxh6fofD+U4+VSZJozS1a2Ma2ppLIF zfD/SaTQ==; Received: from authenticated user by zero.zsh.org with local id 1mxe9W-000D7Y-JL; Wed, 15 Dec 2021 23:57:42 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1mxe8u-000CqH-Q6; Wed, 15 Dec 2021 23:57:05 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.94.2) (envelope-from ) id 1mxe8t-0003tA-N4; Thu, 16 Dec 2021 00:57:03 +0100 cc: Vin Shelton , "Zsh Hackers' List" In-reply-to: From: Oliver Kiddle References: To: Bart Schaefer Subject: Re: segfault in 'ls' completion MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14950.1639612623.1@hydra> Date: Thu, 16 Dec 2021 00:57:03 +0100 Message-ID: <14951-1639612623.711910@AY72.mNNn.Pl2F> X-Seq: 49653 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Bart Schaefer wrote: > I was able to reproduce this I couldn't initially but as you could, I thought I'd better try again. > reverted to revision e40938c128 (before the workers/49499 changes to > computil.c) and was no longer able to reproduce in that version, but that does > also revert some changes to _arguments. It actually seems it was 49518 / 7cb980b which was only applied yesterday having been posted in October and forgotten. I had a nagging suspicion that I needed to further check over that. My mistake was mixing up hex and decimal when looking at the ASCII table to work out how to rearrange the single character option letters within the lookup array. 20 should have been 0x20 or 32. 'y' appears before the tab and the word starts with something that isn't '-'. So it uses the + options offset which are later and as y is within the difference between decimal and hex 20 from the end of the characters this caused it index beyond the end of the array. Following this, I also wondered what it's doing strcmping '/usr/libpy' against every possible ls option. That's nothing new. Note that _arguments only lets you start options with - or + and we check for those explicitly in a few places. I think it's worth optimising this away. The check could perhaps be factored into ca_get_opt() and ca_get_sopt() ? If someone has a moment, please check that the calculation in single_index() makes sense. The array is allocated as ret->single = (Caopt *) zalloc(188 * sizeof(Caopt)); Oliver diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index c49d688c8..59abb4cc4 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -1088,10 +1088,10 @@ bslashcolon(char *s) static int single_index(char pre, char opt) { - if (opt <= 20 || opt > 0x7e) + if (opt <= 0x20 || opt > 0x7e) return -1; - return opt + (pre == '-' ? -21 : 94 - 21); + return opt + (pre == '-' ? -0x21 : 94 - 0x21); } /* Parse an argument definition. */ @@ -2158,7 +2158,8 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) /* See if it's an option. */ - if (state.opt == 2 && (state.curopt = ca_get_opt(d, line, 0, &pe)) && + if (state.opt == 2 && (*line == '-' || *line == '+') && + (state.curopt = ca_get_opt(d, line, 0, &pe)) && (state.curopt->type == CAO_OEQUAL ? (compwords[cur] || pe[-1] == '=') : (state.curopt->type == CAO_EQUAL ? @@ -2206,6 +2207,7 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) state.curopt = NULL; } } else if (state.opt == 2 && d->single && + (*line == '-' || *line == '+') && ((state.curopt = ca_get_sopt(d, line, &pe, &sopts)) || (cur != compcurrent && sopts && nonempty(sopts)))) { /* Or maybe it's a single-letter option? */