You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parser crashes when variable name in let expression is missing #10380
I get index out of bounds crash when typing a program like this:
let = a | b
I ran into this when trying to rename a variable
How to reproduce
Launch nu
Write let = a | b in the terminal
nu immediately crashes
Expected behavior
I expect the parser to not be partial or at least that any panic from the parser would be caught instead of crashing the full shell.
Screenshots
No response
Configuration
key
value
version
0.83.1
branch
commit_hash
build_os
macos-x86_64
build_target
x86_64-apple-darwin
rust_version
rustc 1.71.1 (eb26296b5 2023-08-03) (built from a source tarball)
cargo_version
cargo 1.71.1
build_time
1980-01-01 00:00:00 +00:00
build_rust_channel
release
allocator
standard
features
default, sqlite, trash, which, zip
installed_plugins
Additional context
Stack trace:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', crates/nu-parser/src/parser.rs:3068:47 09/15/2023 10:50:32 AM
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: core::panicking::panic_bounds_check
3: nu_parser::parser::parse_var_with_opt_type
4: nu_parser::parse_keywords::parse_let
5: nu_parser::parser::parse_builtin_commands
6: nu_parser::parser::parse_block
7: nu_parser::parser::parse
8: <nu_cli::syntax_highlight::NuHighlighter as reedline::highlighter::Highlighter>::highlight
9: reedline::engine::Reedline::repaint
10: reedline::engine::Reedline::read_line
11: nu_cli::repl::evaluate_repl
12: nu::run::run_repl
13: nu::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@sholderbach I'm currently working on another way of making the parser code more robust by using primitives that cannot crash instead of sprinkling things like spans[*span_idx] all over the code. See #10381 for my current draft.
Activity
anka-213 commentedon Sep 15, 2023
Here is the line that the stack trace mentions:
nushell/crates/nu-parser/src/parser.rs
Line 3068 in bf5bd3f
It does indeed seem to index an array without checking that it's non-empty first.
anka-213 commentedon Sep 15, 2023
Oh, I see now that it has already been fixed in master, thanks to #9851.
anka-213 commentedon Sep 15, 2023
It would still be nice to do something systematic to prevent this kinds of errors from popping up though
sholderbach commentedon Sep 15, 2023
Yeah more testing and also fuzzing of the parser would definitely be appreciated.
#9417 (comment) proposed a fuzzing target, we should probably set up.
anka-213 commentedon Sep 15, 2023
@sholderbach I'm currently working on another way of making the parser code more robust by using primitives that cannot crash instead of sprinkling things like
spans[*span_idx]all over the code. See #10381 for my current draft.tokatoka commentedon Sep 15, 2023
i'll add it in #10376
sholderbach commentedon Sep 15, 2023
Awesome thanks!