From 3c2bec16cf37437759004bdf240fa6c85bc9e428 Mon Sep 17 00:00:00 2001 From: rorka Date: Tue, 23 Jun 2026 20:38:02 +0300 Subject: refactor: optimize package extraction and harden path traversal protection --- src/info.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/info.rs (limited to 'src/info.rs') diff --git a/src/info.rs b/src/info.rs old mode 100644 new mode 100755 index 0e791fb..d827a53 --- a/src/info.rs +++ b/src/info.rs @@ -5,6 +5,21 @@ use colored::Colorize; const REPO_ROOT: &str = "/var/ror/packages"; +fn find_case_insensitive_dir(parent: &Path, target: &str) -> Option { + let exact = parent.join(target); + if exact.exists() && exact.is_dir() { + return Some(exact); + } + let target_lower = target.to_lowercase(); + for entry in fs::read_dir(parent).ok()? { + let entry = entry.ok()?; + if entry.file_type().ok()?.is_dir() && entry.file_name().to_string_lossy().to_lowercase() == target_lower { + return Some(entry.path()); + } + } + None +} + fn find_package_file(pkg_name: &str) -> Option { let repo = Path::new(REPO_ROOT); for entry in fs::read_dir(repo).ok()? { @@ -13,9 +28,12 @@ fn find_package_file(pkg_name: &str) -> Option { if !cat_path.is_dir() { continue; } - let pkg_path = cat_path.join(pkg_name).join(format!("{}.yaml", pkg_name)); - if pkg_path.exists() && pkg_path.is_file() { - return Some(pkg_path); + if let Some(pkg_dir) = find_case_insensitive_dir(&cat_path, pkg_name) { + let dir_name = pkg_dir.file_name()?.to_string_lossy(); + let pkg_path = pkg_dir.join(format!("{}.yaml", dir_name)); + if pkg_path.exists() && pkg_path.is_file() { + return Some(pkg_path); + } } } None -- cgit v1.2.3