Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Convert scanner style bools to OSP style #1805

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mattmundell
Copy link
Contributor

@mattmundell mattmundell commented Jan 13, 2025

What:

Convert scanner style yes/no boolean preferences to OSP style 1/0 before sending the preferences to ospd.

Why:

I had to do this to get scans to run (using the openvasd-integration branch of gvmd). Maybe helps someone else.

How:

With Rust openvas-scanner main branch, I start a Full and Fast task in GSA. The task sits in Requested and I see Invalid safe_checks value in the openvasd logs:

2025-01-13T22:56:25.950648Z WARN openvasd::scheduling: unable to start, removing from queue and set status to failed. Verify that scan using the API scan_id=1a0299e6-8b6f-428f-9405-7baa393511b4 e=Unexpected issue: InvalidResponse(Status { text: "Invalid safe_checks value", code: StringU64(400) })

openvasd.toml includes:

mode = "service"
[scanner]
type = "ospd"
[storage]
type = "inmemory"

With the PR the scan starts and runs to completion.

References:

Similar conversion is done in launch_osp_openvas_task in manage.c#L2815 in gvmd.

Checklist:

  • Tests
  • PR merge commit message adjusted

@mattmundell mattmundell requested a review from a team as a code owner January 13, 2025 23:10
@@ -188,7 +188,13 @@ fn write_scanner_prefs(scan: &Scan, writer: &mut Writer) -> Result<()> {
writer.write_event(Event::Start(BytesStart::new("scanner_params")))?;
for p in &scan.scan_preferences {
writer.write_event(Event::Start(BytesStart::new(&p.id)))?;
writer.write_event(Event::Text(BytesText::new(&p.value)))?;
let mut value = p.value.as_str();
Copy link
Member

@nichtsfrei nichtsfrei Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In rust you don't need to create a variable before assigning it. It is considered a bad practice.

A better way to handle it would be:

        let value = match p.value.as_ref() {
            "yes" => "1",
            "no" => "0",
            v => v,
        };
        writer.write_event(Event::Text(BytesText::new(value)))?;

This way value does not need to be mutable which makes it a bit easier for the borrow checker when compiling it and for the reader as both don't have to lookout for potential side effects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Philipp, I thought it would need improvement. Changed in ed8f23e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants