mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Denys Vlasenko <vda.linux@googlemail.com>
To: Rich Felker <dalias@libc.org>, musl <musl@lists.openwall.com>
Subject: fnmatch bug? escaping of '-' and ']' inside [...] does not work.
Date: Tue, 15 Aug 2017 15:12:17 +0200	[thread overview]
Message-ID: <CAK1hOcPAE-usFVzRrNMV0QPZPErX8Dww0hA3GjkoC1xAKxXjHA@mail.gmail.com> (raw)

Moving bbox build to musl did uncover one definite bug.
bbox has gazillion tests for its shells, and one of them
started failing. I added debug printout and with it,
the following fnmatch calls give different results now:

ash: fnmatch(pattern:'[a\-c]',str:'-',0):1
ash: fnmatch(pattern:'[\]]',str:']',0):1
ash: fnmatch(pattern:'[a\]]',str:']',0):1

glibc and uclibc threat the above as a match.

The assumption may be that one should place ']' or '-'
as a first character in the [...] and thus escaping
is not necessary, but shell does not have the luxury
of choosing the pattern, in comes from the script.

Just in case you want to know, the complete test is:

# Testing glob-escaping of every ASCII punctuation char
# Some chars have more than one test
# 21..2f
case '!' in [\!] ) echo ok;; *) echo 'WRONG!';; esac
case '"' in [\"] ) echo ok;; *) echo 'WRONG"';; esac
case '#' in [\#] ) echo ok;; *) echo 'WRONG#';; esac
case '$' in [\$] ) echo ok;; *) echo 'WRONG$';; esac
case '%' in [\%] ) echo ok;; *) echo 'WRONG%';; esac
case '&' in [\&] ) echo ok;; *) echo 'WRONG&';; esac
case "'" in [\'] ) echo ok;; *) echo "WRONG'";; esac
case '(' in [\(] ) echo ok;; *) echo 'WRONG(';; esac
case ')' in [\)] ) echo ok;; *) echo 'WRONG)';; esac
case '*' in [\*] ) echo ok;; *) echo 'WRONG*';; esac
case '+' in [\+] ) echo ok;; *) echo 'WRONG+';; esac
case ',' in [\,] ) echo ok;; *) echo 'WRONG,';; esac
case '-' in [\-] ) echo ok;; *) echo 'WRONG-';; esac
case '-' in [a\-c]) echo ok;; *) echo 'WRONGa\-c';; esac
case '.' in [\.] ) echo ok;; *) echo 'WRONG.';; esac
case '/' in [\/] ) echo ok;; *) echo 'WRONG/';; esac
# 3a..40
case ':' in [\:] ) echo ok;; *) echo 'WRONG:';; esac
case ';' in [\;] ) echo ok;; *) echo 'WRONG;';; esac
case '<' in [\<] ) echo ok;; *) echo 'WRONG<';; esac
case '=' in [\=] ) echo ok;; *) echo 'WRONG=';; esac
case '>' in [\>] ) echo ok;; *) echo 'WRONG>';; esac
case '?' in [\?] ) echo ok;; *) echo 'WRONG?';; esac
case '@' in [\@] ) echo ok;; *) echo 'WRONG@';; esac
# 5b..60
case '[' in [\[] ) echo ok;; *) echo 'WRONG[';; esac
case '\' in [\\] ) echo ok;; *) echo 'WRONG\';; esac
case '\' in \\ ) echo ok;; *) echo 'WRONG\\';; esac
case ']' in [\]] ) echo ok;; *) echo 'WRONG]';; esac
case ']' in [a\]]) echo ok;; *) echo 'WRONGa]';; esac
case '^' in [\^] ) echo ok;; *) echo 'WRONG^';; esac
case '_' in [\_] ) echo ok;; *) echo 'WRONG_';; esac
case '`' in [\`] ) echo ok;; *) echo 'WRONG`';; esac
# 7b..7e
case '{' in [\{] ) echo ok;; *) echo 'WRONG{';; esac
case '|' in [\|] ) echo ok;; *) echo 'WRONG|';; esac
case '}' in [\}] ) echo ok;; *) echo 'WRONG}';; esac
case '~' in [\~] ) echo ok;; *) echo 'WRONG~';; esac


             reply	other threads:[~2017-08-15 13:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 13:12 Denys Vlasenko [this message]
2017-08-15 14:25 ` Szabolcs Nagy
2017-08-15 14:28 ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAK1hOcPAE-usFVzRrNMV0QPZPErX8Dww0hA3GjkoC1xAKxXjHA@mail.gmail.com \
    --to=vda.linux@googlemail.com \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).