glibc: Backport hotfixes from RHEL6.
[people/teissler/ipfire-2.x.git] / src / patches / glibc / glibc-rh905874.patch
1 #
2 # Backported from upstream.
3 #
4 # - Add en_US.UTF-8 as pre-requisite for regression test:
5 #
6 # commit 62c4a69dc2aea24776cbf0e951d41709a7408cc6
7 # Author: Joseph Myers <joseph@codesourcery.com>
8 # Date: Thu Nov 1 00:22:04 2012 +0000
9 #
10 # Build en_US.UTF-8 locale for testing.
11 #
12 # - Fix buffer overrun:
13 #
14 # commit a445af0bc722d620afed7683cd320c0e4c7c6059
15 # Author: Andreas Schwab <schwab@suse.de>
16 # Date: Tue Jan 29 14:45:15 2013 +0100
17 #
18 # Fix buffer overrun in regexp matcher
19 #
20 # ChangeLog/
21 # 2013-02-12 Andreas Schwab <schwab@suse.de>
22 #
23 # [BZ #15078]
24 # * posix/regexec.c (extend_buffers): Add parameter min_len.
25 # (check_matching): Pass minimum needed length.
26 # (clean_state_log_if_needed): Likewise.
27 # (get_subexp): Likewise.
28 # * posix/Makefile (tests): Add bug-regex34.
29 # (bug-regex34-ENV): Define.
30 # * posix/bug-regex34.c: New file.
31 #
32 diff -urN glibc-2.12-2-gc4ccff1.orig/localedata/Makefile glibc-2.12-2-gc4ccff1/localedata/Makefile
33 --- glibc-2.12-2-gc4ccff1.orig/localedata/Makefile 2013-07-24 20:40:37.364888120 -0400
34 +++ glibc-2.12-2-gc4ccff1/localedata/Makefile 2013-07-24 20:59:54.713289753 -0400
35 @@ -133,7 +133,7 @@
36 ifeq (no,$(cross-compiling))
37 # We have to generate locales
38 LOCALES := de_DE.ISO-8859-1 de_DE.UTF-8 en_US.ANSI_X3.4-1968 \
39 - en_US.ISO-8859-1 ja_JP.EUC-JP da_DK.ISO-8859-1 \
40 + en_US.ISO-8859-1 en_US.UTF-8 ja_JP.EUC-JP da_DK.ISO-8859-1 \
41 hr_HR.ISO-8859-2 sv_SE.ISO-8859-1 ja_JP.SJIS fr_FR.ISO-8859-1 \
42 vi_VN.TCVN5712-1 nb_NO.ISO-8859-1 nn_NO.ISO-8859-1 \
43 tr_TR.UTF-8 cs_CZ.UTF-8 zh_TW.EUC-TW fa_IR.UTF-8 fr_FR.UTF-8 \
44 diff -urN glibc-2.12-2-gc4ccff1.orig/posix/bug-regex34.c glibc-2.12-2-gc4ccff1/posix/bug-regex34.c
45 --- glibc-2.12-2-gc4ccff1.orig/posix/bug-regex34.c 1969-12-31 19:00:00.000000000 -0500
46 +++ glibc-2.12-2-gc4ccff1/posix/bug-regex34.c 2013-07-24 20:59:54.713289753 -0400
47 @@ -0,0 +1,46 @@
48 +/* Test re_search with multi-byte characters in UTF-8.
49 + Copyright (C) 2013 Free Software Foundation, Inc.
50 + This file is part of the GNU C Library.
51 +
52 + The GNU C Library is free software; you can redistribute it and/or
53 + modify it under the terms of the GNU Lesser General Public
54 + License as published by the Free Software Foundation; either
55 + version 2.1 of the License, or (at your option) any later version.
56 +
57 + The GNU C Library is distributed in the hope that it will be useful,
58 + but WITHOUT ANY WARRANTY; without even the implied warranty of
59 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60 + Lesser General Public License for more details.
61 +
62 + You should have received a copy of the GNU Lesser General Public
63 + License along with the GNU C Library; if not, see
64 + <http://www.gnu.org/licenses/>. */
65 +
66 +#define _GNU_SOURCE 1
67 +#include <stdio.h>
68 +#include <string.h>
69 +#include <locale.h>
70 +#include <regex.h>
71 +
72 +static int
73 +do_test (void)
74 +{
75 + struct re_pattern_buffer r;
76 + /* ကျွန်ုပ်x */
77 + const char *s = "\xe1\x80\x80\xe1\x80\xbb\xe1\x80\xbd\xe1\x80\x94\xe1\x80\xba\xe1\x80\xaf\xe1\x80\x95\xe1\x80\xbax";
78 +
79 + if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
80 + {
81 + puts ("setlocale failed");
82 + return 1;
83 + }
84 + memset (&r, 0, sizeof (r));
85 +
86 + re_compile_pattern ("[^x]x", 5, &r);
87 + /* This was triggering a buffer overflow. */
88 + re_search (&r, s, strlen (s), 0, strlen (s), 0);
89 + return 0;
90 +}
91 +
92 +#define TEST_FUNCTION do_test ()
93 +#include "../test-skeleton.c"
94 diff -urN glibc-2.12-2-gc4ccff1.orig/posix/Makefile glibc-2.12-2-gc4ccff1/posix/Makefile
95 --- glibc-2.12-2-gc4ccff1.orig/posix/Makefile 2013-07-24 20:40:37.399888098 -0400
96 +++ glibc-2.12-2-gc4ccff1/posix/Makefile 2013-07-24 21:00:43.267265979 -0400
97 @@ -94,7 +94,7 @@
98 tst-rfc3484-3 \
99 tst-getaddrinfo3 tst-fnmatch2 tst-cpucount tst-cpuset \
100 bug-getopt1 bug-getopt2 bug-getopt3 bug-getopt4 \
101 - bug-getopt5
102 + bug-getopt5 bug-regex34
103 xtests := bug-ga2
104 ifeq (yes,$(build-shared))
105 test-srcs := globtest
106 @@ -199,6 +199,7 @@
107 bug-regex25-ENV = LOCPATH=$(common-objpfx)localedata
108 bug-regex26-ENV = LOCPATH=$(common-objpfx)localedata
109 bug-regex30-ENV = LOCPATH=$(common-objpfx)localedata
110 +bug-regex34-ENV = LOCPATH=$(common-objpfx)localedata
111 tst-rxspencer-ARGS = --utf8 rxspencer/tests
112 tst-rxspencer-ENV = LOCPATH=$(common-objpfx)localedata
113 tst-pcre-ARGS = PCRE.tests
114 diff -urN glibc-2.12-2-gc4ccff1.orig/posix/regexec.c glibc-2.12-2-gc4ccff1/posix/regexec.c
115 --- glibc-2.12-2-gc4ccff1.orig/posix/regexec.c 2013-07-24 20:40:37.396888100 -0400
116 +++ glibc-2.12-2-gc4ccff1/posix/regexec.c 2013-07-24 21:02:53.005156187 -0400
117 @@ -198,7 +198,7 @@
118 static int check_node_accept (const re_match_context_t *mctx,
119 const re_token_t *node, int idx)
120 internal_function;
121 -static reg_errcode_t extend_buffers (re_match_context_t *mctx)
122 +static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len)
123 internal_function;
124 \f
125 /* Entry point for POSIX code. */
126 @@ -1160,7 +1160,7 @@
127 || (BE (next_char_idx >= mctx->input.valid_len, 0)
128 && mctx->input.valid_len < mctx->input.len))
129 {
130 - err = extend_buffers (mctx);
131 + err = extend_buffers (mctx, next_char_idx + 1);
132 if (BE (err != REG_NOERROR, 0))
133 {
134 assert (err == REG_ESPACE);
135 @@ -1737,7 +1737,7 @@
136 && mctx->input.valid_len < mctx->input.len))
137 {
138 reg_errcode_t err;
139 - err = extend_buffers (mctx);
140 + err = extend_buffers (mctx, next_state_log_idx + 1);
141 if (BE (err != REG_NOERROR, 0))
142 return err;
143 }
144 @@ -2791,7 +2791,7 @@
145 if (bkref_str_off >= mctx->input.len)
146 break;
147
148 - err = extend_buffers (mctx);
149 + err = extend_buffers (mctx, bkref_str_off + 1);
150 if (BE (err != REG_NOERROR, 0))
151 return err;
152
153 @@ -4099,7 +4099,7 @@
154
155 static reg_errcode_t
156 internal_function __attribute_warn_unused_result__
157 -extend_buffers (re_match_context_t *mctx)
158 +extend_buffers (re_match_context_t *mctx, int min_len)
159 {
160 reg_errcode_t ret;
161 re_string_t *pstr = &mctx->input;
162 @@ -4108,8 +4108,10 @@
163 if (BE (INT_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0))
164 return REG_ESPACE;
165
166 - /* Double the lengthes of the buffers. */
167 - ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2);
168 + /* Double the lengthes of the buffers, but allocate at least MIN_LEN. */
169 + ret = re_string_realloc_buffers (pstr,
170 + MAX (min_len,
171 + MIN (pstr->len, pstr->bufs_len * 2)));
172 if (BE (ret != REG_NOERROR, 0))
173 return ret;
174