bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Infinite loop in bash glob matching


From: Eduardo Bustamante
Subject: Re: Infinite loop in bash glob matching
Date: Wed, 17 May 2017 09:52:19 -0500

On Tue, May 16, 2017 at 2:36 PM, Zoltán Herczeg <hzmester@freemail.hu> wrote:
[...]
> bash version: GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
> This command hangs in any directory on my machine (I don't have a directory 
> without a dot file):
>
> ls @(@()).

Yeah, I can reproduce the problem with bash 4.3.11. The empty globs
make bash get stuck inside `extglob_skipname'. This was fixed in
commit 3e8a02a68917250f088a500b09543255364f6f2b
(http://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=3e8a02a68917250f088a500b09543255364f6f2b)

> Yes, glibc seems correct. Do you mean this is a bug in the shell?

I do not think it's a bug. In POSIX's "2.13.1 Patterns Matching a
Single Character"
(http://pubs.opengroup.org/onlinepubs/9699919799.2008edition/utilities/V3_chap02.html#tag_18_13_01),

    If an open bracket introduces a bracket expression as in XBD RE Bracket
    Expression , except that the <exclamation-mark> character ( '!' ) shall
    replace the <circumflex> character ( '^' ) in its role in a non-matching
    list in the regular expression notation, it shall introduce a pattern
    bracket expression. A bracket expression starting with an unquoted
    <circumflex> character produces unspecified results. Otherwise, '[' shall
    match the character itself.

Then in "9.3.5 RE Bracket Expression"
(http://pubs.opengroup.org/onlinepubs/9699919799.2008edition/basedefs/V1_chap09.html#tag_09_03_05),

    The character sequences "[." , "[=" , and "[:" ( <left-square-bracket>
    followed by a <period>, <equals-sign>, or <colon>) shall be special inside
    a bracket expression and are used to delimit collating symbols, equivalence
    class expressions, and character class expressions. These symbols shall be
    followed by a valid expression and the matching terminating sequence ".]" ,
    "=]" , or ":]" , as described in the following items.

So, from my interpretation you can't use the sequence <[><:> like
that, and you should go with Daniel's suggestion instead (i.e.
`a[[:alpha:]:abm[]')

Here's how current shells treat this situation BTW:
    dualbus@debian:~$ for sh in mksh ksh93 dash posh bash; do echo $sh
$($sh -c 'case a in [[:alpha:][:]) echo y;; esac'); done
    mksh
    ksh93
    dash y
    posh
    bash

    dualbus@debian:~$ for sh in mksh ksh93 dash posh bash; do echo $sh
$($sh -c 'case a in [[:alpha:]:[]) echo y;; esac'); done
    mksh
    ksh93 y
    dash y
    posh
    bash y

As you can see, dash is the only one that treats `[[:alpha:][:]' as
<alpha> OR <[> OR :



reply via email to

[Prev in Thread] Current Thread [Next in Thread]