mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
grep: Fix out of bounds StringView indexing
This is another case of out of bounds indexing exposed by 13406b8
.
This commit is contained in:
parent
97cc33ca47
commit
281e46e8b3
Notes:
sideshowbarker
2024-07-17 08:31:30 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/281e46e8b3 Pull-request: https://github.com/SerenityOS/serenity/pull/14717
@ -175,12 +175,14 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
||||
out(colored_output ? "\x1B[35m{}:\x1B[0m"sv : "{}:"sv, line_number);
|
||||
|
||||
for (auto& match : result.matches) {
|
||||
auto pre_match_length = match.global_offset - last_printed_char_pos;
|
||||
out(colored_output ? "{}\x1B[32m{}\x1B[0m"sv : "{}{}"sv,
|
||||
StringView(&str[last_printed_char_pos], match.global_offset - last_printed_char_pos),
|
||||
pre_match_length > 0 ? StringView(&str[last_printed_char_pos], pre_match_length) : ""sv,
|
||||
match.view.to_string());
|
||||
last_printed_char_pos = match.global_offset + match.view.length();
|
||||
}
|
||||
outln("{}", StringView(&str[last_printed_char_pos], str.length() - last_printed_char_pos));
|
||||
auto remaining_length = str.length() - last_printed_char_pos;
|
||||
outln("{}", remaining_length > 0 ? StringView(&str[last_printed_char_pos], remaining_length) : ""sv);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user