Skip to content

Commit

Permalink
Fix segfault with PCRE
Browse files Browse the repository at this point in the history
With PCRE 8.32, doing an invalid search, e.g. `(`, after a succesful one
causes a segfault. Ensure view->regex still contains a valid compiled
regular expression.
  • Loading branch information
koutcher committed Jul 9, 2022
1 parent 162976f commit e9a710d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ draw_view_line(struct view *view, unsigned int lineno)

ok = view->ops->draw(view, line, lineno);

if (ok && line->search_result && view->regex)
if (ok && line->search_result && *view->grep)
draw_view_line_search_result(view, lineno);

return ok;
Expand Down
8 changes: 6 additions & 2 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ find_matches(struct view *view)
/* Note, lineno is unsigned long so will wrap around in which case it
* will become bigger than view->lines. */
for (lineno = 0; lineno < view->lines; lineno++) {
if (!view->ops->grep(view, &view->line[lineno]))
view->line[lineno].search_result = view->ops->grep(view, &view->line[lineno]);

if (!view->line[lineno].search_result)
continue;

if (!realloc_unsigned_ints(&view->matched_line, view->matched_lines, 1))
return false;

view->line[lineno].search_result = true;
view->matched_line[view->matched_lines++] = lineno;
}

Expand Down Expand Up @@ -82,6 +83,9 @@ setup_and_find_next(struct view *view, enum request request)
if (regex_err != 0) {
char buf[SIZEOF_STR] = "unknown error";

/* Clear highlighted results. */
redraw_view_from(view, 0);

regerror(regex_err, view->regex, buf, sizeof(buf));
return error("Search failed: %s", buf);
}
Expand Down

0 comments on commit e9a710d

Please sign in to comment.