From patchwork Wed Sep 16 10:48:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 40412 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3992A397241D; Wed, 16 Sep 2020 10:48:52 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 3F02B3851C3A for ; Wed, 16 Sep 2020 10:48:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3F02B3851C3A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=schwab@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id AC01EACE3 for ; Wed, 16 Sep 2020 10:49:04 +0000 (UTC) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] Fix handling of collating symbols in fnmatch (bug 26620) X-Yow: .. ich bin in einem dusenjet ins jahr 53 vor chr... ich lande im antiken Rom... einige gladiatoren spielen scrabble... ich rieche PIZZA... Date: Wed, 16 Sep 2020 12:48:49 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The variable idx contains the index into the extra array, whereas wextra points into the extra array at this index, containing the length of the following collating sequence in the wide character representation. --- posix/Makefile | 3 ++- posix/fnmatch_loop.c | 4 ++-- posix/tst-fnmatch6.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 posix/tst-fnmatch6.c diff --git a/posix/Makefile b/posix/Makefile index c52645c5f4..19a890742a 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -96,7 +96,7 @@ tests := test-errno tstgetopt testfnm runtests runptests \ bug-getopt5 tst-getopt_long1 bug-regex34 bug-regex35 \ tst-pathconf tst-rxspencer-no-utf8 \ tst-fnmatch3 bug-regex36 \ - tst-fnmatch4 tst-fnmatch5 \ + tst-fnmatch4 tst-fnmatch5 tst-fnmatch6 \ tst-posix_spawn-fd tst-posix_spawn-setsid \ tst-posix_fadvise tst-posix_fadvise64 \ tst-sysconf-empty-chroot tst-glob_symlinks tst-fexecve \ @@ -197,6 +197,7 @@ $(objpfx)bug-regex35.out: $(gen-locales) $(objpfx)tst-fnmatch.out: $(gen-locales) $(objpfx)tst-fnmatch4.out: $(gen-locales) $(objpfx)tst-fnmatch5.out: $(gen-locales) +$(objpfx)tst-fnmatch6.out: $(gen-locales) $(objpfx)tst-regex.out: $(gen-locales) $(objpfx)tst-regex2.out: $(gen-locales) $(objpfx)tst-regexloc.out: $(gen-locales) diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c index 8ead4dc7b9..0f890d4782 100644 --- a/posix/fnmatch_loop.c +++ b/posix/fnmatch_loop.c @@ -564,7 +564,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, /* Get the collation sequence value. */ is_seqval = 1; # if WIDE_CHAR_VERSION - cold = wextra[1 + wextra[idx]]; + cold = wextra[1 + wextra[0]]; # else idx += 1 + extra[idx]; /* Adjust for the alignment. */ @@ -738,7 +738,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, /* Get the collation sequence value. */ is_seqval = 1; # if WIDE_CHAR_VERSION - cend = wextra[1 + wextra[idx]]; + cend = wextra[1 + wextra[0]]; # else idx += 1 + extra[idx]; /* Adjust for the alignment. */ diff --git a/posix/tst-fnmatch6.c b/posix/tst-fnmatch6.c new file mode 100644 index 0000000000..070df69a2c --- /dev/null +++ b/posix/tst-fnmatch6.c @@ -0,0 +1,36 @@ +/* Test for fnmatch handling of collating symbols (bug 26620) + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +static int +do_test (void) +{ + TEST_VERIFY_EXIT (setlocale (LC_ALL, "en_US.UTF-8") != NULL); + /* From iso14651_t1_common: + collating-element from "" + % decomposition of LATIN CAPITAL LETTER L WITH MIDDLE DOT */ + TEST_VERIFY (fnmatch ("[[.L\xc2\xb7.]]", ".", 0) != 0); + TEST_VERIFY (fnmatch ("[[.L\xc2\xb7.]]", "L\xc2\xb7", 0) == 0); + + return 0; +} + +#include