From bf23b2ef4625d8b7cd7665509a5594f91e22bbe8 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 8 Jul 2024 17:56:57 +0800 Subject: [PATCH] vrepl: fix arbitrary script execute (#21818) --- cmd/tools/vrepl.v | 13 ++++--------- vlib/v/slow_tests/repl/error_eval_script.repl | 7 +++++++ 2 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 vlib/v/slow_tests/repl/error_eval_script.repl diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 41a79ea5c..e36424127 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -353,15 +353,6 @@ fn run_repl(workdir string, vrepl_prefix string) int { if line.len <= -1 || line == 'exit' { break } - if exit_pos := line.index('exit') { - oparen := line[(exit_pos + 4)..].trim_space() - if oparen.starts_with('(') { - if closing := oparen.index(')') { - rc := oparen[1..closing].parse_int(0, 8) or { panic(err) } - return int(rc) - } - } - } r.line = line if r.line == '\n' { continue @@ -470,6 +461,10 @@ fn run_repl(workdir string, vrepl_prefix string) int { if oline.starts_with(' ') { is_statement = true } + // The parentheses do not match + if r.line.count('(') != r.line.count(')') { + is_statement = true + } if !is_statement && (!func_call || fntype == FnType.fn_type) && r.line != '' { temp_line = 'println(${r.line})' source_code := r.current_source_code(false, false) + '\n${temp_line}\n' diff --git a/vlib/v/slow_tests/repl/error_eval_script.repl b/vlib/v/slow_tests/repl/error_eval_script.repl new file mode 100644 index 000000000..316944a93 --- /dev/null +++ b/vlib/v/slow_tests/repl/error_eval_script.repl @@ -0,0 +1,7 @@ +"text") exit(-1) +===output=== +error: expression evaluated but not used + 5 | import math + 6 | + 7 | "text") exit(-1) + | ~~~~~~ -- 2.39.5