You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
expand_cpu_range collects (start..=end) into a Vec with no upper bound on the range size. A value like -C 0-99999999999 from the CLI or max_cpu_usage_vec: ["0-99999999999"] in the config file will attempt to allocate a Vec of ~100 billion u64 entries, causing memory exhaustion and an OOM abort. Consider validating that end - start stays within a sane bound (e.g., the number of CPUs on the system, or a small constant) before collecting.
The doc comment for the Init command reads "Change directory for generated Suriconf configuration file", which describes the previous semantics of a different command and does not match what Init does (generate the default Suriconf configuration file). This text becomes the CLI help output shown by -h/--help, so it will confuse users of the newly documented suriconf init command.
/// Change directory for generated Suriconf configuration fileInit{
The function only supports single values or single ranges, but typical CPU-set syntax (both for Suricata and common CLI usage) is comma-separated, e.g. 0-2,5,7. Input like 0-2,5 currently fails to parse and causes a panic via the caller's .expect(). Split on commas first and expand each part, so combined range/list expressions are handled correctly.
fn expand_cpu_range(s: &str) -> Option<Vec<u64>> {
let s = s.trim();
- match s.split_once('-') {- Some((start, end)) => {- let start: u64 = start.trim().parse().ok()?;- let end: u64 = end.trim().parse().ok()?;- (start <= end).then(|| (start..=end).collect())+ let mut cpus = Vec::new();+ for part in s.split(',') {+ let part = part.trim();+ if part.is_empty() {+ return None;
}
- None => Some(vec![s.parse().ok()?]),+ match part.split_once('-') {+ Some((start, end)) => {+ let start: u64 = start.trim().parse().ok()?;+ let end: u64 = end.trim().parse().ok()?;+ if start > end {+ return None;+ }+ cpus.extend(start..=end);+ }+ None => cpus.push(part.parse().ok()?),+ }
}
+ Some(cpus)
}
Suggestion importance[1-10]: 5
__
Why: The current expand_cpu_range fails on inputs like 0-2,5, and such a token could appear via a single CLI argument or a string value in the YAML sequence, causing a panic. The improved code correctly implements comma-splitting, but since the CLI uses space as value_delimiter and YAML sequences are already split, this is a robustness enhancement rather than a critical bug.
Low
General
Handle init errors gracefully without panicking
Panicking on a user-facing error such as a refused overwrite or unwritable path prints a noisy "thread panicked" backtrace instead of a clean CLI message. Print the error to stderr and exit with a non-zero status code, consistent with typical CLI behavior.
if let Some(Commands::Init { output, force }) = &args.cmd {
if let Err(e) = init(output, *force) {
- panic!("{e}");+ eprintln!("Error: {e}");+ process::exit(1);
}
process::exit(0);
}
Suggestion importance[1-10]: 5
__
Why: Replacing panic! with eprintln! and a non-zero exit code gives a clean CLI error message without a backtrace, which is appropriate for user-facing errors like a refused overwrite. It is a valid but non-critical error-handling improvement.
Low
Create output parent directories in init
fs::write fails with a raw OS error if the target directory does not exist, which is likely when users pass a nested path like ./config/suriconf.yaml. Create parent directories before writing so the --output option works for any valid path.
pub fn init(output: &PathBuf, force: bool) -> io::Result<()> {
if output.exists() && !force {
return Err(io::Error::new(
io::ErrorKind::AlreadyExists,
format!("refusing to overwrite {:?} (use --force)", output),
));
}
+ if let Some(parent) = output.parent() {+ if !parent.as_os_str().is_empty() {+ fs::create_dir_all(parent)?;+ }+ }
fs::write(output, DEFAULT_CONFIG)?;
Ok(())
}
Suggestion importance[1-10]: 5
__
Why: fs::write will fail for nested output paths like ./config/suriconf.yaml when the directory does not exist, and the suggested fs::create_dir_all on the parent fixes that. The change is correct and low-risk, but only affects non-default output paths, so impact is moderate.
Low
Include invalid input in parse error message
When parsing fails, this panics with a generic message that does not indicate which value was invalid, making CLI usage errors hard to diagnose (e.g. --cpu 8-x or an empty token). Include the offending input in the error so users can immediately see what failed to parse.
self.max_cpu_usage_vec = if let Some(Commands::Var { max_cpu_usage_vec: Some(max_cpu_usage_vec), .. }) = &args.cmd {
- parse_cpu_list(&max_cpu_usage_vec).expect("Unable to parse max cpu usage vector.")+ parse_cpu_list(&max_cpu_usage_vec)+ .unwrap_or_else(|| panic!("Unable to parse max cpu usage vector: {max_cpu_usage_vec:?}."))
} else {
Suggestion importance[1-10]: 3
__
Why: Including the offending max_cpu_usage_vec values in the panic message is a small diagnostic improvement that helps users identify malformed input like --cpu 8-x. The suggestion is accurate but offers only a marginal improvement to error reporting.
Low
Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement, Documentation
Description
Add
initcommand generating default configuration fileSupport CPU range expansion in
max_cpu_usage_vecDocument required Suricata branch and commit
Bump version to 1.0.2-dev
Diagram Walkthrough
File Walkthrough
5 files
Add CPU range parsing and expansion helpersAdd Init subcommand and string CPU listHandle init command before main workflowNew module writing default config fileRegister config_gen module and DEFAULT_CONFIG constant2 files
Update Suricata version, branch, and init usageMinor updates to issues documentation2 files
Bump version and update default pathsBump package version to 1.0.2-dev3 files