Skip to content

fix: validate single-label VM name early in CLI and JSON-RPC - #234

Open
codeXsidd wants to merge 3 commits into
openai:mainfrom
codeXsidd:fix/issue-233-validate-vm-name
Open

codeXsidd wants to merge 3 commits into
openai:mainfrom
codeXsidd:fix/issue-233-validate-vm-name

Conversation

@codeXsidd

Copy link
Copy Markdown

Summary

Add early validation of the --vm-name CLI argument and the JSON-RPC name field in softnet.initialize, ensuring invalid VM names are rejected before startup / manager dispatch.

Problem

Softnet's DNS server (DnsServer::new) enforces that VM names must be single-label (no dots), non-FQDN, and non-wildcard. However, neither the CLI --vm-name argument nor the JSON-RPC softnet.initialize name field validated this constraint at parse time. This meant:

  1. CLI: Passing --vm-name foo.bar accepted the argument, started the process, and only then crashed inside manager initialization with invalid VM name foo.bar: expected a single DNS label.
  2. JSON-RPC: A softnet.initialize call with "name": "foo.bar" was dispatched to the manager and returned a CALL_EXECUTION_FAILED_CODE (-32000) instead of the expected INVALID_PARAMS_CODE (-32602).

Solution

  • lib/dns_server/mod.rs: Extracted the single-label validation into a new public is_valid_vm_name() helper function. Also refactored DnsServer::new to use it instead of an inline check.
  • lib/mod.rs: Made the dns_server module pub so src/main.rs can import the helper.
  • lib/control.rs: Imported is_valid_vm_name and applied it in parse_initialize when parsing the optional VM name field, returning INVALID_PARAMS_CODE on failure.
  • src/main.rs: Replaced the inline |value: &str| Name::from_ascii(value) lambda with a dedicated parse_vm_name function that also calls is_valid_vm_name, producing a clear clap error before startup.

Testing

  • New CLI tests in src/main.rs:
    • test_cli_rejects_multi_label_vm_name_before_startup: verifies foo.bar, foo.internal., and *.foo all fail during argument parsing with an appropriate error message.
    • test_cli_accepts_single_label_vm_name: verifies a valid single-label name like myvm is accepted.
  • New JSON-RPC test cases added to the existing rejects_invalid_initialization_and_closes_every_descriptor test in lib/control_test.rs:
    • Multi-label name foo.bar → INVALID_PARAMS_CODE.
    • FQDN name foo.internal. → INVALID_PARAMS_CODE.

Tests run via CI (macOS-only build/test environment); the local environment is Windows and does not have a Rust toolchain installed.

Related Issue

Closes #233

Copilot AI balanced review requested due to automatic review settings November 2, 2026 04:44
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T04:57:52.165877Z b7ca52b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One API-surface suggestion: lib/mod.rs makes the entire dns_server module public solely so the binary can call is_valid_vm_name. Could we keep mod dns_server; private and re-export just the helper (pub use dns_server::is_valid_vm_name;), with src/main.rs importing it from softnet? That preserves the existing module boundary while still sharing the exact validator between the CLI, RPC parser, and DNS server.

@codeXsidd

Copy link
Copy Markdown
Author

Updated in b7ca52b: kept \dns_server\ private in \lib/mod.rs\ and re-exported \is_valid_vm_name\ from the crate root via \pub use dns_server::is_valid_vm_name;, with \src/main.rs\ importing from \softnet::is_valid_vm_name. Thanks for the suggestion!

This branch has not been deployed

No deployments
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.

Validate single-label VM name before startup in CLI and JSON-RPC initialization

3 participants