mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:27:35 +00: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
1 changed files with 4 additions and 2 deletions
|
@ -175,12 +175,14 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
||||||
out(colored_output ? "\x1B[35m{}:\x1B[0m"sv : "{}:"sv, line_number);
|
out(colored_output ? "\x1B[35m{}:\x1B[0m"sv : "{}:"sv, line_number);
|
||||||
|
|
||||||
for (auto& match : result.matches) {
|
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,
|
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());
|
match.view.to_string());
|
||||||
last_printed_char_pos = match.global_offset + match.view.length();
|
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;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue