# HG changeset patch # User Markus Mützel # Date 1656963408 -7200 # Node ID d8d90ba892b03e8aaf8434324f01a674cb6ffdae # Parent bc62d4ad2aae6dead3d5f06854cafa632a66fcc6# Parent 5cf18ef0377ccf457a90d135f091f17ea5afbaad maint: Merge stable to default. diff -r bc62d4ad2aae -r d8d90ba892b0 libinterp/corefcn/regexp.cc --- a/libinterp/corefcn/regexp.cc Wed Jun 29 19:07:59 2022 +0200 +++ b/libinterp/corefcn/regexp.cc Mon Jul 04 21:36:48 2022 +0200 @@ -912,6 +912,7 @@ ## segfault test %!assert (regexp ("abcde", "."), [1,2,3,4,5]) +%!assert <*62704> (regexpi('(', '\(?'), 1) ## Infinite loop test %!assert (isempty (regexp ("abcde", ""))) diff -r bc62d4ad2aae -r d8d90ba892b0 liboctave/util/lo-regexp.cc --- a/liboctave/util/lo-regexp.cc Wed Jun 29 19:07:59 2022 +0200 +++ b/liboctave/util/lo-regexp.cc Mon Jul 04 21:36:48 2022 +0200 @@ -83,9 +83,11 @@ while ((new_pos = m_pattern.find ("(?", pos)) != std::string::npos) { - if (m_pattern.at (new_pos + 2) == '<' - && !(m_pattern.at (new_pos + 3) == '=' - || m_pattern.at (new_pos + 3) == '!')) + if (m_pattern.size () > new_pos + 2 + && m_pattern.at (new_pos + 2) == '<' + && ! (m_pattern.size () > new_pos + 3 + && (m_pattern.at (new_pos + 3) == '=' + || m_pattern.at (new_pos + 3) == '!'))) { // The syntax of named tokens in pcre is "(?P...)" while // we need a syntax "(?...)", so fix that here. Also an @@ -137,7 +139,8 @@ pos = tmp_pos; } - else if (m_pattern.at (new_pos + 2) == '<') + else if (m_pattern.size () > new_pos + 2 + && m_pattern.at (new_pos + 2) == '<') { // Find lookbehind operators of arbitrary length (ie like // "(?<=[a-z]*)") and replace with a maximum length operator