mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
Shell: Correct the out-of-bounds expansion bailing condition
Also adds a couple (useful) debug prints which helped track down the problem.
This commit is contained in:
parent
d56fbaa7e8
commit
99d264afbe
Notes:
sideshowbarker
2024-07-17 08:25:15 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/99d264afbe Pull-request: https://github.com/SerenityOS/serenity/pull/17493
1 changed files with 4 additions and 1 deletions
|
@ -1682,10 +1682,13 @@ RefPtr<AST::Node> Parser::parse_word()
|
|||
append_bareword(string.substring_view(*run_start, string.length() - *run_start));
|
||||
};
|
||||
|
||||
if (!token.resolved_expansions.is_empty())
|
||||
dbgln_if(SHELL_POSIX_PARSER_DEBUG, "Expanding '{}' with {} expansion entries", token.value, token.resolved_expansions.size());
|
||||
size_t current_offset = 0;
|
||||
for (auto& expansion : token.resolved_expansions) {
|
||||
expansion.visit(
|
||||
[&](ResolvedParameterExpansion const& x) {
|
||||
dbgln_if(SHELL_POSIX_PARSER_DEBUG, " Expanding '{}' ({}+{})", x.to_deprecated_string(), x.range.start, x.range.length);
|
||||
if (x.range.start >= token.value.length()) {
|
||||
dbgln("Parameter expansion range {}-{} is out of bounds for '{}'", x.range.start, x.range.length, token.value);
|
||||
return;
|
||||
|
@ -1713,7 +1716,7 @@ RefPtr<AST::Node> Parser::parse_word()
|
|||
});
|
||||
}
|
||||
|
||||
if (current_offset >= token.value.length()) {
|
||||
if (current_offset > token.value.length()) {
|
||||
dbgln("Parameter expansion range {}- is out of bounds for '{}'", current_offset, token.value);
|
||||
return word;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue