Skip to content

Replace Unimplemented Revert Aux-Hook with No-Op and Handle current_dir Resolution Errors - #704

Open
mozluk wants to merge 1 commit into
Quantus-Network:mainfrom
mozluk:mozluk-patch-1
Open

mozluk wants to merge 1 commit into
Quantus-Network:mainfrom
mozluk:mozluk-patch-1

Conversation

@mozluk

@mozluk mozluk commented Sep 14, 2026

Copy link
Copy Markdown

Description

This pull request resolves medium- and low-severity CLI panic vectors in chain identified during the Quantus workspace security audit (FM-13, FM-14).

Previously, invoking the revert subcommand triggered an unimplemented!() panic when executing consensus auxiliary data revert logic (leftover from Grandpa's removal)[cite: 49]. Additionally, resolving a relative path passed via --node-key-file relied on an unhandled std::env::current_dir().unwrap(), which panicked if the working directory was invalid or deleted[cite: 49].

Key Changes & Remediations

1. Safe No-Op Consensus Revert Hook (FM-13 - node/src/command.rs)

  • Eliminated unimplemented!() Panic: Replaced the unimplemented Grandpa consensus revert closure with a deliberate no-op closure returning Ok(()): ```rust let aux_revert = Box::new( |_client, _, _blocks| -> Result<(), sc_cli::Error> { Ok(()) }, );

Upstream Type Alignment: Conforms strictly to upstream sc_cli::AuxRevertHandler (Box<dyn FnOnce(...) -> Result<(), sc_cli::Error>>), allowing chain reverts to complete cleanly without crashing the node process[cite: 49].

2. Graceful Relative Node Key Resolution

(FM-14 - node/src/command.rs)Eliminated current_dir().unwrap(): Replaced .unwrap() with explicit error mapping via .map_err(...). Descriptive Input Error: Maps working directory lookup failures to sc_cli::Error::Input with an informative error message instead of an unhandled panic[cite: 49, 61].

How to Review

Inspect node/src/command.rs under Some(Subcommand::Revert(cmd)) to verify the no-op aux_revert closure. Inspect the relative path resolution branch for --node-key-file to verify the error mapping around std::env::current_dir().

…dir` Resolution Errors

### Description
This pull request resolves medium- and low-severity CLI panic vectors in `chain` identified during the Quantus workspace security audit (**FM-13, FM-14**).

Previously, invoking the `revert` subcommand triggered an `unimplemented!()` panic when executing consensus auxiliary data revert logic (leftover from Grandpa's removal)[cite: 49]. Additionally, resolving a relative path passed via `--node-key-file` relied on an unhandled `std::env::current_dir().unwrap()`, which panicked if the working directory was invalid or deleted[cite: 49].

### Key Changes & Remediations

#### 1. Safe No-Op Consensus Revert Hook (FM-13 - `node/src/command.rs`)
* **Eliminated `unimplemented!()` Panic:** Replaced the unimplemented Grandpa consensus revert closure with a deliberate no-op closure returning `Ok(())`:
  ```rust
  let aux_revert = Box::new(
      |_client, _, _blocks| -> Result<(), sc_cli::Error> { Ok(()) },
  );

Upstream Type Alignment: Conforms strictly to upstream sc_cli::AuxRevertHandler (Box<dyn FnOnce(...) -> Result<(), sc_cli::Error>>), allowing chain reverts to complete cleanly without crashing the node process[cite: 49].2. Graceful Relative Node Key Resolution (FM-14 - node/src/command.rs)Eliminated current_dir().unwrap(): Replaced .unwrap() with explicit error mapping via .map_err(...).  Descriptive Input Error: Maps working directory lookup failures to sc_cli::Error::Input with an informative error message instead of an unhandled panic[cite: 49, 61].How to ReviewInspect node/src/command.rs under Some(Subcommand::Revert(cmd)) to verify the no-op aux_revert closure.  Inspect the relative path resolution branch for --node-key-file to verify the error mapping around std::env::current_dir().

@n13 n13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Question on the first item

Second item is good, and agree with that

Comment thread node/src/command.rs
let aux_revert = Box::new(|_client, _, _blocks| {
unimplemented!("TODO - g*randpa was removed.");
});
// Grandpa was removed from this chain, so there is no consensus

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

General policy is to fail early vs hide bugs

I think it's better to throw, which is why we're throwing.

Why did you make this change?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If anything, a nice error message would be better, we don't want to ignore this

Comment thread node/src/command.rs
} else {
// This is a valid assumption because the node is run from the shell
std::env::current_dir().unwrap().join(path)
// This is a valid assumption because the node is run from the shell;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This change is good

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