SHA256
3
0
forked from pool/glibc

Accepting request 664336 from home:Andreas_Schwab:Factory

- fnmatch-collating-elements.patch: update
- riscv-flush-icache.patch: fix for compiling against 4.20 headers

OBS-URL: https://build.opensuse.org/request/show/664336
OBS-URL: https://build.opensuse.org/package/show/Base:System/glibc?expand=0&rev=515
This commit is contained in:
Andreas Schwab 2019-01-10 11:21:29 +00:00 committed by Git OBS Bridge
parent d0ecab50fd
commit c8985eb9db
4 changed files with 192 additions and 74 deletions

View File

@ -1,4 +1,8 @@
Fix fnmatch handling of collating elements (BZ #17396, BZ #16976)
Fix handling of collating elements in fnmatch (bug 17396, bug 16976)
This fixes the same bug in fnmatch that was fixed by commit 7e2f0d2d77 for
regexp matching. As a side effect it also removes the use of an unbound
VLA.
[BZ #16976]
[BZ #17396]
@ -6,15 +10,34 @@ Fix fnmatch handling of collating elements (BZ #17396, BZ #16976)
looking up collating elements match against (wide) character
sequence instead of name. Correct alignment adjustment.
* posix/fnmatch.c: Don't include "../locale/elem-hash.h".
(WMEMCMP) [HANDLE_MULTIBYTE]: Define.
* posix/Makefile (tests): Add tst-fnmatch4 and tst-fnmatch5.
(LOCALES): Add cs_CZ.ISO-8859-2.
* posix/tst-fnmatch4.c: New file.
* posix/tst-fnmatch5.c: New file.
* include/wchar.h (__wmemcmp): Declare.
* wcsmbs/wmemcmp.c: Define __wmemcmp and add wmemcmp as weak alias.
* sysdeps/i386/i686/multiarch/wmemcmp.c: Likewise.
* sysdeps/x86_64/multiarch/wmemcmp.c: Likewise.
* sysdeps/s390/wmemcmp.c: Likewise.
Index: glibc-2.27/posix/Makefile
Index: glibc-2.28/include/wchar.h
===================================================================
--- glibc-2.27.orig/posix/Makefile
+++ glibc-2.27/posix/Makefile
--- glibc-2.28.orig/include/wchar.h
+++ glibc-2.28/include/wchar.h
@@ -143,6 +143,8 @@ libc_hidden_proto (wmemchr)
libc_hidden_proto (__wmemchr)
libc_hidden_proto (wmemset)
libc_hidden_proto (__wmemset)
+extern int __wmemcmp (const wchar_t *__s1, const wchar_t *__s2, size_t __n)
+ __THROW __attribute_pure__;
/* Now define the internal interfaces. */
extern int __wcscasecmp (const wchar_t *__s1, const wchar_t *__s2)
Index: glibc-2.28/posix/Makefile
===================================================================
--- glibc-2.28.orig/posix/Makefile
+++ glibc-2.28/posix/Makefile
@@ -92,6 +92,7 @@ tests := test-errno tstgetopt testfnm r
bug-getopt5 tst-getopt_long1 bug-regex34 bug-regex35 \
tst-pathconf tst-rxspencer-no-utf8 \
@ -23,7 +46,7 @@ Index: glibc-2.27/posix/Makefile
tst-posix_spawn-fd tst-posix_spawn-setsid \
tst-posix_fadvise tst-posix_fadvise64 \
tst-sysconf-empty-chroot tst-glob_symlinks tst-fexecve \
@@ -165,7 +166,8 @@ $(objpfx)wordexp-tst.out: wordexp-tst.sh $(objpfx)wordexp-test
@@ -166,7 +167,8 @@ $(objpfx)wordexp-tst.out: wordexp-tst.sh
endif
LOCALES := cs_CZ.UTF-8 da_DK.ISO-8859-1 de_DE.ISO-8859-1 de_DE.UTF-8 \
@ -33,10 +56,10 @@ Index: glibc-2.27/posix/Makefile
include ../gen-locales.mk
$(objpfx)bug-regex1.out: $(gen-locales)
Index: glibc-2.27/posix/fnmatch.c
Index: glibc-2.28/posix/fnmatch.c
===================================================================
--- glibc-2.27.orig/posix/fnmatch.c
+++ glibc-2.27/posix/fnmatch.c
--- glibc-2.28.orig/posix/fnmatch.c
+++ glibc-2.28/posix/fnmatch.c
@@ -53,7 +53,6 @@
we support a correct implementation only in glibc. */
#ifdef _LIBC
@ -45,10 +68,22 @@ Index: glibc-2.27/posix/fnmatch.c
# include "../locale/coll-lookup.h"
# include <shlib-compat.h>
Index: glibc-2.27/posix/fnmatch_loop.c
@@ -237,6 +236,11 @@ __wcschrnul (const wchar_t *s, wint_t c)
# define MEMPCPY(D, S, N) __wmempcpy (D, S, N)
# define MEMCHR(S, C, N) __wmemchr (S, C, N)
# define STRCOLL(S1, S2) wcscoll (S1, S2)
+# ifdef _LIBC
+# define WMEMCMP(S1, S2, N) __wmemcmp (S1, S2, N)
+# else
+# define WMEMCMP(S1, S2, N) wmemcmp (S1, S2, N)
+# endif
# define WIDE_CHAR_VERSION 1
/* Change the name the header defines so it doesn't conflict with
the <locale/weight.h> version included above. */
Index: glibc-2.28/posix/fnmatch_loop.c
===================================================================
--- glibc-2.27.orig/posix/fnmatch_loop.c
+++ glibc-2.27/posix/fnmatch_loop.c
--- glibc-2.28.orig/posix/fnmatch_loop.c
+++ glibc-2.28/posix/fnmatch_loop.c
@@ -494,26 +494,12 @@ FCT (const CHAR *pattern, const CHAR *st
{
int32_t table_size;
@ -73,12 +108,12 @@ Index: glibc-2.27/posix/fnmatch_loop.c
- for (strcnt = 0; strcnt < c1; ++strcnt)
- str[strcnt] = startp[1 + strcnt];
-#endif
+ int32_t *wextra;
+ CHAR *wextra;
+# endif
table_size =
_NL_CURRENT_WORD (LC_COLLATE,
@@ -525,71 +511,55 @@ FCT (const CHAR *pattern, const CHAR *st
@@ -525,71 +511,54 @@ FCT (const CHAR *pattern, const CHAR *st
_NL_CURRENT (LC_COLLATE,
_NL_COLLATE_SYMB_EXTRAMB);
@ -126,13 +161,13 @@ Index: glibc-2.27/posix/fnmatch_loop.c
+ /* Adjust for the alignment. */
+ idx = (idx + 3) & ~3;
+
+ wextra = (int32_t *) &extra[idx + 4];
+ wextra = (CHAR *) &extra[idx + 4];
+
+ if (/* Compare the length of the sequence. */
+ c1 == wextra[0]
+ /* Compare the wide char sequence. */
+ && memcmp (startp + 1, &wextra[1],
+ c1 * sizeof (UCHAR)) == 0)
+ && WMEMCMP (startp + 1, &wextra[1],
+ c1) == 0)
+ /* Yep, this is the entry. */
+ break;
+# else
@ -153,12 +188,12 @@ Index: glibc-2.27/posix/fnmatch_loop.c
this is not part of a range. */
-# if WIDE_CHAR_VERSION
- int32_t *wextra;
+ if (! is_range
-
- idx += 1 + extra[idx];
- /* Adjust for the alignment. */
- idx = (idx + 3) & ~3;
-
+ if (! is_range
- wextra = (int32_t *) &extra[idx + 4];
-# endif
-
@ -173,8 +208,7 @@ Index: glibc-2.27/posix/fnmatch_loop.c
-
- if ((int32_t) c1 == wextra[idx])
- goto matched;
+ && memcmp (n, &wextra[1],
+ c1 * sizeof (UCHAR)) == 0
+ && WMEMCMP (n, &wextra[1], c1) == 0
# else
- for (c1 = 0; c1 < extra[idx]; ++c1)
- if (n[c1] != extra[1 + c1])
@ -191,7 +225,7 @@ Index: glibc-2.27/posix/fnmatch_loop.c
}
/* Get the collation sequence value. */
@@ -597,9 +567,9 @@ FCT (const CHAR *pattern, const CHAR *st
@@ -597,9 +566,9 @@ FCT (const CHAR *pattern, const CHAR *st
# if WIDE_CHAR_VERSION
cold = wextra[1 + wextra[idx]];
# else
@ -203,7 +237,7 @@ Index: glibc-2.27/posix/fnmatch_loop.c
cold = *((int32_t *) &extra[idx]);
# endif
@@ -609,10 +579,10 @@ FCT (const CHAR *pattern, const CHAR *st
@@ -609,10 +578,10 @@ FCT (const CHAR *pattern, const CHAR *st
{
/* No valid character. Match it as a
single byte. */
@ -216,7 +250,7 @@ Index: glibc-2.27/posix/fnmatch_loop.c
c = *p++;
}
else
@@ -620,7 +590,6 @@ FCT (const CHAR *pattern, const CHAR *st
@@ -620,7 +589,6 @@ FCT (const CHAR *pattern, const CHAR *st
}
}
else
@ -224,7 +258,7 @@ Index: glibc-2.27/posix/fnmatch_loop.c
#endif
{
c = FOLD (c);
@@ -712,25 +681,11 @@ FCT (const CHAR *pattern, const CHAR *st
@@ -712,25 +680,11 @@ FCT (const CHAR *pattern, const CHAR *st
{
int32_t table_size;
const int32_t *symb_table;
@ -247,11 +281,11 @@ Index: glibc-2.27/posix/fnmatch_loop.c
- representation is UCS4. */
- for (strcnt = 0; strcnt < c1; ++strcnt)
- str[strcnt] = startp[1 + strcnt];
+ int32_t *wextra;
+ CHAR *wextra;
# endif
table_size =
@@ -743,51 +698,44 @@ FCT (const CHAR *pattern, const CHAR *st
@@ -743,71 +697,63 @@ FCT (const CHAR *pattern, const CHAR *st
_NL_CURRENT (LC_COLLATE,
_NL_COLLATE_SYMB_EXTRAMB);
@ -312,14 +346,14 @@ Index: glibc-2.27/posix/fnmatch_loop.c
+ /* Adjust for the alignment. */
+ idx = (idx + 3) & ~3;
+
+ wextra = (int32_t *) &extra[idx + 4];
+ wextra = (CHAR *) &extra[idx + 4];
+
+ if (/* Compare the length of the
+ sequence. */
+ c1 == wextra[0]
+ /* Compare the wide char sequence. */
+ && memcmp (startp + 1, &wextra[1],
+ c1 * sizeof (int32_t)) == 0)
+ && WMEMCMP (startp + 1, &wextra[1],
+ c1) == 0)
+ /* Yep, this is the entry. */
+ break;
+# else
@ -339,11 +373,12 @@ Index: glibc-2.27/posix/fnmatch_loop.c
/* Get the collation sequence value. */
is_seqval = 1;
# if WIDE_CHAR_VERSION
@@ -795,19 +743,18 @@ FCT (const CHAR *pattern, const CHAR *st
cend = wextra[1 + wextra[idx]];
# else
/* Adjust for the alignment. */
- /* Adjust for the alignment. */
idx += 1 + extra[idx];
- idx = (idx + 3) & ~4;
+ /* Adjust for the alignment. */
+ idx = (idx + 3) & ~3;
cend = *((int32_t *) &extra[idx]);
# endif
@ -362,13 +397,13 @@ Index: glibc-2.27/posix/fnmatch_loop.c
}
else
{
Index: glibc-2.27/posix/tst-fnmatch4.c
Index: glibc-2.28/posix/tst-fnmatch4.c
===================================================================
--- /dev/null
+++ glibc-2.27/posix/tst-fnmatch4.c
@@ -0,0 +1,51 @@
+++ glibc-2.28/posix/tst-fnmatch4.c
@@ -0,0 +1,41 @@
+/* Test for fnmatch handling of collating elements
+ Copyright (C) 2015 Free Software Foundation, Inc.
+ Copyright (C) 2019 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
@ -388,43 +423,33 @@ Index: glibc-2.27/posix/tst-fnmatch4.c
+#include <stdio.h>
+#include <locale.h>
+#include <fnmatch.h>
+#include <support/check.h>
+
+static int
+static void
+do_test_locale (const char *locale)
+{
+ const char *pattern = "[[.ch.]]";
+ TEST_VERIFY_EXIT (setlocale (LC_ALL, locale) != NULL);
+
+ if (setlocale (LC_ALL, locale) == NULL)
+ {
+ printf ("could not set locale %s\n", locale);
+ return 1;
+ }
+
+ if (fnmatch (pattern, "ch", 0) != 0)
+ {
+ printf ("%s didn't match in locale %s\n", pattern, locale);
+ return 1;
+ }
+
+ return 0;
+ TEST_VERIFY (fnmatch ("[[.ch.]]", "ch", 0) == 0);
+}
+
+static int
+do_test (void)
+{
+ return (do_test_locale ("cs_CZ.ISO-8859-2")
+ || do_test_locale ("cs_CZ.UTF-8"));
+ do_test_locale ("cs_CZ.ISO-8859-2");
+ do_test_locale ("cs_CZ.UTF-8");
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
Index: glibc-2.27/posix/tst-fnmatch5.c
+#include <support/test-driver.c>
Index: glibc-2.28/posix/tst-fnmatch5.c
===================================================================
--- /dev/null
+++ glibc-2.27/posix/tst-fnmatch5.c
@@ -0,0 +1,53 @@
+++ glibc-2.28/posix/tst-fnmatch5.c
@@ -0,0 +1,46 @@
+/* Test for fnmatch handling of collating elements
+ Copyright (C) 2015 Free Software Foundation, Inc.
+ Copyright (C) 2019 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
@ -445,19 +470,17 @@ Index: glibc-2.27/posix/tst-fnmatch5.c
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <support/check.h>
+
+#define LENGTH 20000000
+
+char pattern[LENGTH + 7];
+static char pattern[LENGTH + 7];
+
+static int
+do_test (void)
+{
+ if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
+ {
+ puts ("could not set locale");
+ return 1;
+ }
+ TEST_VERIFY_EXIT (setlocale (LC_ALL, "en_US.UTF-8") != NULL);
+
+ pattern[0] = '[';
+ pattern[1] = '[';
+ pattern[2] = '.';
@ -465,14 +488,74 @@ Index: glibc-2.27/posix/tst-fnmatch5.c
+ pattern[LENGTH + 3] = '.';
+ pattern[LENGTH + 4] = ']';
+ pattern[LENGTH + 5] = ']';
+ int ret = fnmatch (pattern, "a", 0);
+ if (ret == 0)
+ {
+ puts ("fnmatch returned 0 for invalid pattern");
+ return 1;
+ }
+ TEST_VERIFY (fnmatch (pattern, "a", 0) != 0);
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
+#include <support/test-driver.c>
Index: glibc-2.28/sysdeps/i386/i686/multiarch/wmemcmp.c
===================================================================
--- glibc-2.28.orig/sysdeps/i386/i686/multiarch/wmemcmp.c
+++ glibc-2.28/sysdeps/i386/i686/multiarch/wmemcmp.c
@@ -26,5 +26,6 @@
# define SYMBOL_NAME wmemcmp
# include "ifunc-ssse3-sse4_2.h"
-libc_ifunc_redirected (__redirect_wmemcmp, wmemcmp, IFUNC_SELECTOR ());
+libc_ifunc_redirected (__redirect_wmemcmp, __wmemcmp, IFUNC_SELECTOR ());
+weak_alias (__wmemcmp, wmemcmp)
#endif
Index: glibc-2.28/sysdeps/s390/multiarch/wmemcmp.c
===================================================================
--- glibc-2.28.orig/sysdeps/s390/multiarch/wmemcmp.c
+++ glibc-2.28/sysdeps/s390/multiarch/wmemcmp.c
@@ -20,7 +20,8 @@
# include <wchar.h>
# include <ifunc-resolve.h>
-s390_vx_libc_ifunc2 (__wmemcmp, wmemcmp)
+s390_vx_libc_ifunc (__wmemcmp)
+weak_alias (__wmemcmp, wmemcmp)
#else
# include <wcsmbs/wmemcmp.c>
Index: glibc-2.28/sysdeps/x86_64/multiarch/wmemcmp.c
===================================================================
--- glibc-2.28.orig/sysdeps/x86_64/multiarch/wmemcmp.c
+++ glibc-2.28/sysdeps/x86_64/multiarch/wmemcmp.c
@@ -26,5 +26,6 @@
# define SYMBOL_NAME wmemcmp
# include "ifunc-memcmp.h"
-libc_ifunc_redirected (__redirect_wmemcmp, wmemcmp, IFUNC_SELECTOR ());
+libc_ifunc_redirected (__redirect_wmemcmp, __wmemcmp, IFUNC_SELECTOR ());
+weak_alias (__wmemcmp, wmemcmp)
#endif
Index: glibc-2.28/wcsmbs/wmemcmp.c
===================================================================
--- glibc-2.28.orig/wcsmbs/wmemcmp.c
+++ glibc-2.28/wcsmbs/wmemcmp.c
@@ -18,12 +18,12 @@
#include <wchar.h>
-#ifndef WMEMCMP
-# define WMEMCMP wmemcmp
+#ifdef WMEMCMP
+# define __wmemcmp WMEMCMP
#endif
int
-WMEMCMP (const wchar_t *s1, const wchar_t *s2, size_t n)
+__wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
{
wchar_t c1;
wchar_t c2;
@@ -81,3 +81,6 @@ WMEMCMP (const wchar_t *s1, const wchar_
return 0;
}
+#ifndef WMEMCMP
+weak_alias (__wmemcmp, wmemcmp)
+#endif

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Jan 9 14:21:04 UTC 2019 - schwab@suse.de
- fnmatch-collating-elements.patch: update
- riscv-flush-icache.patch: fix for compiling against 4.20 headers
-------------------------------------------------------------------
Wed Nov 28 09:52:49 UTC 2018 - schwab@suse.de

View File

@ -1,7 +1,7 @@
#
# spec file for package glibc
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -292,6 +292,8 @@ Patch1009: pthread-mutex-lock-elision-race.patch
Patch1010: x86-haswell-string-flags.patch
# PATCH-FIX-UPSTREAM if_nametoindex: Fix descriptor leak for overlong name (CVE-2018-19591, BZ #23927)
Patch1011: if-nametoindex-descr-leak.patch
# PATCH-FIX-UPSTREAM riscv: Use __has_include__ to include <asm/syscalls.h> (BZ #24022)
Patch1012: riscv-flush-icache.patch
###
# Patches awaiting upstream approval
@ -513,6 +515,7 @@ makedb: A program to create a database for nss
%patch1009 -p1
%patch1010 -p1
%patch1011 -p1
%patch1012 -p1
%patch2000 -p1
%patch2004 -p1

26
riscv-flush-icache.patch Normal file
View File

@ -0,0 +1,26 @@
2018-12-31 H.J. Lu <hongjiu.lu@intel.com>
[BZ #24022]
* sysdeps/unix/sysv/linux/riscv/flush-icache.c: Check if
<asm/syscalls.h> exists with __has_include__ before including it.
diff --git a/sysdeps/unix/sysv/linux/riscv/flush-icache.c b/sysdeps/unix/sysv/linux/riscv/flush-icache.c
index d612ef4c6c..0b2042620b 100644
--- a/sysdeps/unix/sysv/linux/riscv/flush-icache.c
+++ b/sysdeps/unix/sysv/linux/riscv/flush-icache.c
@@ -21,7 +21,11 @@
#include <stdlib.h>
#include <atomic.h>
#include <sys/cachectl.h>
-#include <asm/syscalls.h>
+#if __has_include__ (<asm/syscalls.h>)
+# include <asm/syscalls.h>
+#else
+# include <asm/unistd.h>
+#endif
typedef int (*func_type) (void *, void *, unsigned long int);
--
2.20.1