diff options
| author | rorka <rorka@rorka.my.domain> | 2026-06-23 20:38:02 +0300 |
|---|---|---|
| committer | rorka <rorka@rorka.my.domain> | 2026-06-23 20:38:02 +0300 |
| commit | 3c2bec16cf37437759004bdf240fa6c85bc9e428 (patch) | |
| tree | 42c760a8dcd878cfee91c41958874c23b8bc7889 /src/info.rs | |
| parent | f726a6920d85f149efeae9ca1624138e9e374938 (diff) | |
| download | ror-3c2bec16cf37437759004bdf240fa6c85bc9e428.tar.gz ror-3c2bec16cf37437759004bdf240fa6c85bc9e428.zip | |
refactor: optimize package extraction and harden path traversal protection
Diffstat (limited to 'src/info.rs')
| -rwxr-xr-x[-rw-r--r--] | src/info.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/info.rs b/src/info.rs index 0e791fb..d827a53 100644..100755 --- 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<PathBuf> { + 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<PathBuf> { 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<PathBuf> { 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 |