Skip to content

Commit caeae0f

Browse files
szledandbatyai
authored andcommitted
Fix undefined result in RegExp engine
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai.u-szeged@partner.samsung.com JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan szledan.u-szeged@partner.samsung.com
1 parent c17197d commit caeae0f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

jerry-core/ecma/operations/ecma-regexp-object.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,11 +1213,15 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
12131213
JERRY_ASSERT (re_ctx.num_of_captures % 2 == 0);
12141214
re_ctx.num_of_non_captures = re_get_value (&bc_p);
12151215

1216+
/* We create an invalid iterator, that will be used to identify unused result values. */
1217+
lit_utf8_iterator_t unused_iter = lit_utf8_iterator_create (NULL, 0);
1218+
unused_iter.buf_p = (lit_utf8_byte_t *) 1;
1219+
12161220
MEM_DEFINE_LOCAL_ARRAY (saved_p, re_ctx.num_of_captures + re_ctx.num_of_non_captures, lit_utf8_iterator_t);
12171221

12181222
for (uint32_t i = 0; i < re_ctx.num_of_captures + re_ctx.num_of_non_captures; i++)
12191223
{
1220-
saved_p[i] = lit_utf8_iterator_create (NULL, 0);
1224+
saved_p[i] = unused_iter;
12211225
}
12221226
re_ctx.saved_p = saved_p;
12231227

@@ -1317,9 +1321,8 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
13171321
{
13181322
ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i / 2);
13191323

1320-
/* Note: 'iterator.buf_p == NULL' means the input is empty string */
1321-
if (((re_ctx.saved_p[i].buf_p && re_ctx.saved_p[i + 1].buf_p)
1322-
|| (!iterator.buf_p && !re_ctx.saved_p[i].buf_p && !re_ctx.saved_p[i + 1].buf_p))
1324+
/* Note: 'iter_p->buf_p == NULL' means the input is empty string */
1325+
if ((re_ctx.saved_p[i].buf_p != unused_iter.buf_p && re_ctx.saved_p[i + 1].buf_p != unused_iter.buf_p)
13231326
&& re_ctx.saved_p[i + 1].buf_pos.offset >= re_ctx.saved_p[i].buf_pos.offset)
13241327
{
13251328
ecma_length_t capture_str_len;

0 commit comments

Comments
 (0)