diff --git a/CHANGELOG.md b/CHANGELOG.md index f62371be..b4981cf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v5.0.x: + +- **FIX**: fix risk of crash/corruption in help mode reverse search + ## v5.0.0 - **FIX**: fix off-by-one error in `P.ROT` understanding of pattern length diff --git a/docs/whats_new.md b/docs/whats_new.md index 46e7a073..4dabecc0 100644 --- a/docs/whats_new.md +++ b/docs/whats_new.md @@ -1,5 +1,9 @@ # Updates +## v5.0.x + +- **FIX**: fix risk of crash/corruption in help mode reverse search + ## v5.0.0 - **FIX**: fix off-by-one error in `P.ROT` understanding of pattern length diff --git a/module/help_mode.c b/module/help_mode.c index 422c5131..f5d328bb 100644 --- a/module/help_mode.c +++ b/module/help_mode.c @@ -1692,6 +1692,9 @@ bool text_search_forward(search_state_t* state, const char* needle, bool text_search_reverse(search_state_t* state, const char* needle, const char** haystack, int haystack_len) { const int needle_len = strlen(needle); + if (state->line >= haystack_len) { + state->line = haystack_len - 1; + } for (; state->line >= 0; state->line--) { const int haystack_line_len = strlen(haystack[state->line]); for (state->ch = haystack_line_len - needle_len; state->ch >= 0;