Skip to content

Commit dd0e53e

Browse files
committed
dialplan: fix copying subst's out vector
(cherry picked from commit 30825e4)
1 parent c48acc8 commit dd0e53e

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

modules/dialplan/dp_repl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,21 +440,21 @@ int test_match(str string, pcre2_code * exp, int * out, int out_max)
440440
}
441441

442442
ovector = pcre2_get_ovector_pointer(match_data);
443-
for (i = 0; i < result_count; i++)
444-
{
445-
// avoid buffer overflow
446-
if (i >= out_max)
447-
break;
443+
if (2 * result_count >= out_max)
444+
result_count = out_max / 2;
448445

449-
// ovector is freed by pcre2_match_data_free, copy offsets to out[]
446+
// ovector is freed by pcre2_match_data_free, copy offsets to out[]
447+
for (i = 0; i < result_count * 2; i++)
450448
out[i] = ovector[i];
449+
pcre2_match_data_free(match_data);
451450

451+
for (i = 0; i < result_count; i++)
452+
{
452453
substring_start = string.s + out[2 * i];
453454
substring_length = out[2 * i + 1] - out[2 * i];
454455
LM_DBG("test_match:[%d] %.*s\n",i, substring_length, substring_start);
455456
}
456457

457-
pcre2_match_data_free(match_data);
458458
return result_count;
459459
}
460460

0 commit comments

Comments
 (0)