Contents of /trunk/glibc/patches/glibc-2.17-regexp-matcher-overrun.patch
Parent Directory | Revision Log
Revision 2233 -
(show annotations)
(download)
Thu Jul 11 17:04:32 2013 UTC (11 years, 2 months ago) by niro
File size: 5018 byte(s)
Thu Jul 11 17:04:32 2013 UTC (11 years, 2 months ago) by niro
File size: 5018 byte(s)
-more patches
1 | diff --git a/posix/Makefile b/posix/Makefile |
2 | index 88d409f..2cacd21 100644 |
3 | --- a/posix/Makefile |
4 | +++ b/posix/Makefile |
5 | @@ -86,7 +86,7 @@ tests := tstgetopt testfnm runtests runptests \ |
6 | tst-rfc3484-3 \ |
7 | tst-getaddrinfo3 tst-fnmatch2 tst-cpucount tst-cpuset \ |
8 | bug-getopt1 bug-getopt2 bug-getopt3 bug-getopt4 \ |
9 | - bug-getopt5 tst-getopt_long1 |
10 | + bug-getopt5 tst-getopt_long1 bug-regex34 |
11 | xtests := bug-ga2 |
12 | ifeq (yes,$(build-shared)) |
13 | test-srcs := globtest |
14 | @@ -199,5 +199,6 @@ bug-regex26-ENV = LOCPATH=$(common-objpfx)localedata |
15 | bug-regex30-ENV = LOCPATH=$(common-objpfx)localedata |
16 | bug-regex32-ENV = LOCPATH=$(common-objpfx)localedata |
17 | bug-regex33-ENV = LOCPATH=$(common-objpfx)localedata |
18 | +bug-regex34-ENV = LOCPATH=$(common-objpfx)localedata |
19 | tst-rxspencer-ARGS = --utf8 rxspencer/tests |
20 | tst-rxspencer-ENV = LOCPATH=$(common-objpfx)localedata |
21 | diff --git a/posix/bug-regex34.c b/posix/bug-regex34.c |
22 | new file mode 100644 |
23 | index 0000000..bb3b613 |
24 | --- /dev/null |
25 | +++ b/posix/bug-regex34.c |
26 | @@ -0,0 +1,46 @@ |
27 | +/* Test re_search with multi-byte characters in UTF-8. |
28 | + Copyright (C) 2013 Free Software Foundation, Inc. |
29 | + This file is part of the GNU C Library. |
30 | + |
31 | + The GNU C Library is free software; you can redistribute it and/or |
32 | + modify it under the terms of the GNU Lesser General Public |
33 | + License as published by the Free Software Foundation; either |
34 | + version 2.1 of the License, or (at your option) any later version. |
35 | + |
36 | + The GNU C Library is distributed in the hope that it will be useful, |
37 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
38 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
39 | + Lesser General Public License for more details. |
40 | + |
41 | + You should have received a copy of the GNU Lesser General Public |
42 | + License along with the GNU C Library; if not, see |
43 | + <http://www.gnu.org/licenses/>. */ |
44 | + |
45 | +#define _GNU_SOURCE 1 |
46 | +#include <stdio.h> |
47 | +#include <string.h> |
48 | +#include <locale.h> |
49 | +#include <regex.h> |
50 | + |
51 | +static int |
52 | +do_test (void) |
53 | +{ |
54 | + struct re_pattern_buffer r; |
55 | + /* áá»á½ááºá¯ááºx */ |
56 | + 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"; |
57 | + |
58 | + if (setlocale (LC_ALL, "en_US.UTF-8") == NULL) |
59 | + { |
60 | + puts ("setlocale failed"); |
61 | + return 1; |
62 | + } |
63 | + memset (&r, 0, sizeof (r)); |
64 | + |
65 | + re_compile_pattern ("[^x]x", 5, &r); |
66 | + /* This was triggering a buffer overflow. */ |
67 | + re_search (&r, s, strlen (s), 0, strlen (s), 0); |
68 | + return 0; |
69 | +} |
70 | + |
71 | +#define TEST_FUNCTION do_test () |
72 | +#include "../test-skeleton.c" |
73 | diff --git a/posix/regexec.c b/posix/regexec.c |
74 | index 7f2de85..5ca2bf6 100644 |
75 | --- a/posix/regexec.c |
76 | +++ b/posix/regexec.c |
77 | @@ -197,7 +197,7 @@ static int group_nodes_into_DFAstates (const re_dfa_t *dfa, |
78 | static int check_node_accept (const re_match_context_t *mctx, |
79 | const re_token_t *node, int idx) |
80 | internal_function; |
81 | -static reg_errcode_t extend_buffers (re_match_context_t *mctx) |
82 | +static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len) |
83 | internal_function; |
84 | |
85 | /* Entry point for POSIX code. */ |
86 | @@ -1160,7 +1160,7 @@ check_matching (re_match_context_t *mctx, int fl_longest_match, |
87 | || (BE (next_char_idx >= mctx->input.valid_len, 0) |
88 | && mctx->input.valid_len < mctx->input.len)) |
89 | { |
90 | - err = extend_buffers (mctx); |
91 | + err = extend_buffers (mctx, next_char_idx + 1); |
92 | if (BE (err != REG_NOERROR, 0)) |
93 | { |
94 | assert (err == REG_ESPACE); |
95 | @@ -1738,7 +1738,7 @@ clean_state_log_if_needed (re_match_context_t *mctx, int next_state_log_idx) |
96 | && mctx->input.valid_len < mctx->input.len)) |
97 | { |
98 | reg_errcode_t err; |
99 | - err = extend_buffers (mctx); |
100 | + err = extend_buffers (mctx, next_state_log_idx + 1); |
101 | if (BE (err != REG_NOERROR, 0)) |
102 | return err; |
103 | } |
104 | @@ -2792,7 +2792,7 @@ get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx) |
105 | if (bkref_str_off >= mctx->input.len) |
106 | break; |
107 | |
108 | - err = extend_buffers (mctx); |
109 | + err = extend_buffers (mctx, bkref_str_off + 1); |
110 | if (BE (err != REG_NOERROR, 0)) |
111 | return err; |
112 | |
113 | @@ -4102,7 +4102,7 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node, |
114 | |
115 | static reg_errcode_t |
116 | internal_function __attribute_warn_unused_result__ |
117 | -extend_buffers (re_match_context_t *mctx) |
118 | +extend_buffers (re_match_context_t *mctx, int min_len) |
119 | { |
120 | reg_errcode_t ret; |
121 | re_string_t *pstr = &mctx->input; |
122 | @@ -4111,8 +4111,10 @@ extend_buffers (re_match_context_t *mctx) |
123 | if (BE (INT_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0)) |
124 | return REG_ESPACE; |
125 | |
126 | - /* Double the lengthes of the buffers. */ |
127 | - ret = re_string_realloc_buffers (pstr, MIN (pstr->len, pstr->bufs_len * 2)); |
128 | + /* Double the lengthes of the buffers, but allocate at least MIN_LEN. */ |
129 | + ret = re_string_realloc_buffers (pstr, |
130 | + MAX (min_len, |
131 | + MIN (pstr->len, pstr->bufs_len * 2))); |
132 | if (BE (ret != REG_NOERROR, 0)) |
133 | return ret; |
134 | |
135 | -- |
136 | 1.7.1 |
137 |