Skip to content

Commit

Permalink
vrepl: fix arbitrary script execute (vlang#21818)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Jul 8, 2024
1 parent 14d378c commit bf23b2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 4 additions & 9 deletions cmd/tools/vrepl.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/slow_tests/repl/error_eval_script.repl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"text") exit(-1)
===output===
error: expression evaluated but not used
5 | import math
6 |
7 | "text") exit(-1)
| ~~~~~~

0 comments on commit bf23b2e

Please sign in to comment.