Skip to content

Commit 3394de1

Browse files
committed
fixed crashing of bad regexps,
due to attempt to reference a compiled regexp, which has not been compiled due to some error, by b2::regex::program::result_iterator::advance
1 parent 6e61515 commit 3394de1

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/engine/regexp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,19 +1151,19 @@ bool regex_exec(
11511151

11521152
void regerror(char const * s) { out_printf("re error %s\n", s); }
11531153

1154-
regex_prog & program::compile(const char * pattern)
1154+
regex_prog * program::compile(const char * pattern)
11551155
{
11561156
static std::unordered_map<std::string, regex_prog_ptr> cache;
11571157
if (cache.count(pattern) == 0)
11581158
{
11591159
cache[pattern] = regex_comp(pattern);
11601160
}
1161-
return *cache[pattern];
1161+
return cache[pattern].get();
11621162
}
11631163

11641164
program::program(const char * pattern) { reset(pattern); }
11651165

1166-
void program::reset(const char * pattern) { compiled = &compile(pattern); }
1166+
void program::reset(const char * pattern) { compiled = compile(pattern); }
11671167

11681168
program::result_iterator::result_iterator(
11691169
const regex_prog & c, const string_view & s)
@@ -1176,7 +1176,7 @@ program::result_iterator::result_iterator(
11761176
void program::result_iterator::advance()
11771177
{
11781178
// We start searching for a match at the end of the previous match.
1179-
if (regex_exec(*compiled, expressions, rest))
1179+
if ((compiled != nullptr) && regex_exec(*compiled, expressions, rest))
11801180
{
11811181
// A match means the subexpressions are filled in and the first entry
11821182
// is the full match. Advance `rest` to follow the match.

src/engine/regexp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct program
5252
private:
5353
const regex_prog * compiled = nullptr;
5454

55-
static regex_prog & compile(const char * patter);
55+
static regex_prog * compile(const char * patter);
5656
};
5757

5858
struct program::result_iterator

0 commit comments

Comments
 (0)