88 lines
3.1 KiB
Diff
88 lines
3.1 KiB
Diff
|
When extending regex buffers, make sure we allocate enough room for the
|
|||
|
state log. Merely doubling the space may not be enough if the current
|
|||
|
node has accepted a long run of characters. This part of the code only
|
|||
|
triggers with multibyte characters.
|
|||
|
|
|||
|
Andreas.
|
|||
|
|
|||
|
[BZ #15078]
|
|||
|
* posix/regexec.c (extend_buffers): Add parameter min_len.
|
|||
|
(check_matching): Pass minimum needed length.
|
|||
|
(clean_state_log_if_needed): Likewise.
|
|||
|
(get_subexp): Likewise.
|
|||
|
* posix/Makefile (tests): Add bug-regex34.
|
|||
|
(bug-regex34-ENV): Define.
|
|||
|
* posix/bug-regex34.c: New file.
|
|||
|
|
|||
|
diff --git a/posix/regexec.c b/posix/regexec.c
|
|||
|
index 7f2de85..5ca2bf6 100644
|
|||
|
--- a/posix/regexec.c
|
|||
|
+++ b/posix/regexec.c
|
|||
|
@@ -197,7 +197,7 @@ static int group_nodes_into_DFAstates (const re_dfa_t *dfa,
|
|||
|
static int check_node_accept (const re_match_context_t *mctx,
|
|||
|
const re_token_t *node, int idx)
|
|||
|
internal_function;
|
|||
|
-static reg_errcode_t extend_buffers (re_match_context_t *mctx)
|
|||
|
+static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len)
|
|||
|
internal_function;
|
|||
|
|
|||
|
/* Entry point for POSIX code. */
|
|||
|
@@ -1160,7 +1160,7 @@ check_matching (re_match_context_t *mctx, int fl_longest_match,
|
|||
|
|| (BE (next_char_idx >= mctx->input.valid_len, 0)
|
|||
|
&& mctx->input.valid_len < mctx->input.len))
|
|||
|
{
|
|||
|
- err = extend_buffers (mctx);
|
|||
|
+ err = extend_buffers (mctx, next_char_idx + 1);
|
|||
|
if (BE (err != REG_NOERROR, 0))
|
|||
|
{
|
|||
|
assert (err == REG_ESPACE);
|
|||
|
@@ -1738,7 +1738,7 @@ clean_state_log_if_needed (re_match_context_t *mctx, int next_state_log_idx)
|
|||
|
&& mctx->input.valid_len < mctx->input.len))
|
|||
|
{
|
|||
|
reg_errcode_t err;
|
|||
|
- err = extend_buffers (mctx);
|
|||
|
+ err = extend_buffers (mctx, next_state_log_idx + 1);
|
|||
|
if (BE (err != REG_NOERROR, 0))
|
|||
|
return err;
|
|||
|
}
|
|||
|
@@ -2792,7 +2792,7 @@ get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx)
|
|||
|
if (bkref_str_off >= mctx->input.len)
|
|||
|
break;
|
|||
|
|
|||
|
- err = extend_buffers (mctx);
|
|||
|
+ err = extend_buffers (mctx, bkref_str_off + 1);
|
|||
|
if (BE (err != REG_NOERROR, 0))
|
|||
|
return err;
|
|||
|
|
|||
|
@@ -4102,7 +4102,7 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
|
|||
|
|
|||
|
static reg_errcode_t
|
|||
|
internal_function __attribute_warn_unused_result__
|
|||
|
-extend_buffers (re_match_context_t *mctx)
|
|||
|
+extend_buffers (re_match_context_t *mctx, int min_len)
|
|||
|
{
|
|||
|
reg_errcode_t ret;
|
|||
|
re_string_t *pstr = &mctx->input;
|
|||
|
@@ -4111,8 +4111,10 @@ extend_buffers (re_match_context_t *mctx)
|
|||
|
if (BE (INT_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0))
|
|||
|
return REG_ESPACE;
|
|||
|
|
|||
|
- /* Double the lengthes of the buffers. */
|
|||
|
- ret = re_string_realloc_buffers (pstr, MIN (pstr->len, pstr->bufs_len * 2));
|
|||
|
+ /* Double the lengthes of the buffers, but allocate at least MIN_LEN. */
|
|||
|
+ ret = re_string_realloc_buffers (pstr,
|
|||
|
+ MAX (min_len,
|
|||
|
+ MIN (pstr->len, pstr->bufs_len * 2)));
|
|||
|
if (BE (ret != REG_NOERROR, 0))
|
|||
|
return ret;
|
|||
|
|
|||
|
--
|
|||
|
1.8.1.2
|
|||
|
|
|||
|
|
|||
|
--
|
|||
|
Andreas Schwab, SUSE Labs, schwab@suse.de
|
|||
|
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
|
|||
|
"And now for something completely different."
|
|||
|
|