From patchwork Sat Sep 3 13:58:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 9312021 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5141F60756 for ; Sat, 3 Sep 2016 13:59:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38FB6291C3 for ; Sat, 3 Sep 2016 13:59:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D9EB2921D; Sat, 3 Sep 2016 13:59:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2411E291C3 for ; Sat, 3 Sep 2016 13:59:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753487AbcICN7P (ORCPT ); Sat, 3 Sep 2016 09:59:15 -0400 Received: from helcar.hengli.com.au ([209.40.204.226]:56218 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753146AbcICN7P (ORCPT ); Sat, 3 Sep 2016 09:59:15 -0400 Received: from gondolin.me.apana.org.au ([192.168.0.6]) by norbury.hengli.com.au with esmtp (Exim 4.80 #3 (Debian)) id 1bgBTF-0003b5-S7; Sat, 03 Sep 2016 23:58:57 +1000 Received: from herbert by gondolin.me.apana.org.au with local (Exim 4.80) (envelope-from ) id 1bgBT9-0005H9-Hf; Sat, 03 Sep 2016 21:58:51 +0800 Date: Sat, 3 Sep 2016 21:58:50 +0800 From: Herbert Xu To: Harald van Dijk Cc: Eric Blake , olof@ethup.se, dash@vger.kernel.org Subject: Re: Parameter expansion, patterns and fnmatch Message-ID: <20160903135850.GA20234@gondor.apana.org.au> References: <20160902140437.GA12639@gondor.apana.org.au> <6f39229b-7196-afd9-8e8f-3db1c33bf80a@redhat.com> <20160902142928.GA13022@gondor.apana.org.au> <20160902145153.GA13458@gondor.apana.org.au> <20160903130506.GA19749@gondor.apana.org.au> <1acf6563-5a42-2bfa-ac7a-fbdd2c315b85@gigawatt.nl> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1acf6563-5a42-2bfa-ac7a-fbdd2c315b85@gigawatt.nl> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Sat, Sep 03, 2016 at 03:19:57PM +0200, Harald van Dijk wrote: > > But yeah, sure, if the bug has been there for over 10 years, and I'm > unable to find older versions of dash to check, I would have guessed > that dash indeed has never worked this way. OK it looks like this actually wasn't the original behaviour. It was introduced along with the character class support. So with that in mind, I feel a lot happier in changing the behaviour of the case statement. I've changed your patch slightly and will commit it if there are no other issues. ---8<--- Subject: expand - Fix dangling left square brackets in patterns When there is an unmatched left square bracket in patterns, pmatch will behave strangely and exhibit undefined behaviour. This patch (based on Harld van Dijk's original) fixes this by treating it as a literal left square bracket. Reported-by: Olof Johansson Signed-off-by: Herbert Xu diff --git a/src/expand.c b/src/expand.c index 36bea76..2a50830 100644 --- a/src/expand.c +++ b/src/expand.c @@ -1584,14 +1584,14 @@ pmatch(const char *pattern, const char *string) p++; } found = 0; - chr = *q++; + chr = *q; if (chr == '\0') return 0; c = *p++; do { if (!c) { p = startp; - c = *p; + c = '['; goto dft; } if (c == '[') { @@ -1618,6 +1618,7 @@ pmatch(const char *pattern, const char *string) } while ((c = *p++) != ']'); if (found == invert) return 0; + q++; break; } dft: default: