Skip to content

Commit

Permalink
Previously, running a script like
Browse files Browse the repository at this point in the history
```
display("foo");
exit(3);
display("bar");
```

with `scannerctl execute script` would result in "foo" and "bar" being printed.
This was because all statements were interpreted first, their respective
results collected into a `Vec` and `scannerctl` would then iterate over
the results and log them. This is clearly not the intended behavior,
since it causes all side effects in the builtin functions to run
regardless of whether the script exits or not.

This commit fixes this bug by iterating over the results that the stream
returns and exiting when `NaslValue::Exit` is encountered, causing any
subsequent statements not to run.
  • Loading branch information
Tehforsch committed Dec 4, 2024
1 parent 5cfa721 commit 31508c2
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions rust/src/scannerctl/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,8 @@ where
.build(ContextKey::Scan(self.scan_id.clone(), target));
let register = RegisterBuilder::build();
let code = self.load(script)?;
let results: Vec<_> = CodeInterpreter::new(&code, register, &context)
.stream()
.collect()
.await;
for result in results {
let mut results = CodeInterpreter::new(&code, register, &context).stream();
while let Some(result) = results.next().await {
let r = match result {
Ok(x) => x,
Err(e) => match &e.kind {
Expand Down

0 comments on commit 31508c2

Please sign in to comment.