From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11818 Path: news.gmane.org!.POSTED!not-for-mail From: Denys Vlasenko Newsgroups: gmane.linux.lib.musl.general Subject: fnmatch bug? escaping of '-' and ']' inside [...] does not work. Date: Tue, 15 Aug 2017 15:12:17 +0200 Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1502802780 6725 195.159.176.226 (15 Aug 2017 13:13:00 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 15 Aug 2017 13:13:00 +0000 (UTC) To: Rich Felker , musl Original-X-From: musl-return-11831-gllmg-musl=m.gmane.org@lists.openwall.com Tue Aug 15 15:12:56 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dhbeM-0001E8-M2 for gllmg-musl@m.gmane.org; Tue, 15 Aug 2017 15:12:50 +0200 Original-Received: (qmail 25624 invoked by uid 550); 15 Aug 2017 13:12:53 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 24562 invoked from network); 15 Aug 2017 13:12:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=iYto8kQN+KnhB8M1GWfE/ltq0kk5WT7sD2mr3GeqNOo=; b=X8/enH3D7fhCWa1joAGmZQDRyJ5MtWpZNCxSTV1+mR1iKv6kYMbkIQK+lPMsylRmCP UvVCd9P1gVoJGbDCORetr+9TcQTAnL25PjXWv2fgRkw3nTsiqfP7M+WLmwOlkAemivVF bHsY8w8JgSimYUSadRdlCJfvhbEHYzldD9kS7dgtz5GGyWPhVmuQSQXF45eZXS0tNlyl 4mjiFFj5oN5vYJQHAX8GItWJC1OFARmv47Z6rEbeto5J/WRLUEnkkjcEa926aliRZvx4 v6mbDx5M8oMt3xzcypIZVVD3fMmc7IsLfVE+G0z19STevJMynsc1JePzGqAusEdApzWM yPew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=iYto8kQN+KnhB8M1GWfE/ltq0kk5WT7sD2mr3GeqNOo=; b=KLXlT6kmudkSSnbaRfP1RyYxl1L3ymHBIfesjX0zvNNZFZS5HDlFKLnNsdE/T/VDDd YaZLBmbT1FwndclvXrYeOmnO4eBW1tQCHIoKDSAuC0skpsnvPyNKXLwvxjaB8Gob2IAS 7aF95cNlI/RYZ82qsCAM/CNJIYrSKP2DnARHt/xWxqHrCnLs1bG00u/OtZAok9p7njZM CEVw9MQqF56BcsGN8hXz/nGtL00YWQUVfwD3WGm/9SqhjU22ZNMKDJTcawWIppQA7Z1B 7IketoNBF9EITLdDl8jmCYfAVUPv7HQdISRl6OLyTfE03KlJBq0mO/FarTleP0NQmEJZ xfXQ== X-Gm-Message-State: AHYfb5jrceV5dek5QHdtsTEmUVMp4IwWrOOmbFwt2RR67WWb6CxV3wMH Mbnf4Lu7ZwNqHEA6Vl3Uzv/WbA9wTQ== X-Received: by 10.80.169.165 with SMTP id n34mr27899694edc.232.1502802758282; Tue, 15 Aug 2017 06:12:38 -0700 (PDT) Xref: news.gmane.org gmane.linux.lib.musl.general:11818 Archived-At: 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