pxar: split assert_relative_path
the check for a single component is only required in the dir stack atm Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
c443f58b09
commit
7eacdc765b
@ -21,7 +21,7 @@ use proxmox::tools::fd::RawFdNum;
|
||||
|
||||
use crate::pxar::catalog::BackupCatalogWriter;
|
||||
use crate::pxar::flags;
|
||||
use crate::pxar::tools::assert_relative_path;
|
||||
use crate::pxar::tools::assert_single_path_component;
|
||||
use crate::tools::{acl, fs, xattr, Fd};
|
||||
|
||||
fn detect_fs_type(fd: RawFd) -> Result<i64, Error> {
|
||||
@ -230,7 +230,7 @@ impl<'a, 'b> Archiver<'a, 'b> {
|
||||
}
|
||||
|
||||
let os_file_name = OsStr::from_bytes(file_name_bytes);
|
||||
assert_relative_path(os_file_name)?;
|
||||
assert_single_path_component(os_file_name)?;
|
||||
let full_path = self.path.join(os_file_name);
|
||||
|
||||
let stat = match nix::sys::stat::fstatat(
|
||||
|
@ -10,7 +10,7 @@ use nix::sys::stat::{mkdirat, Mode};
|
||||
use proxmox::sys::error::SysError;
|
||||
use pxar::Metadata;
|
||||
|
||||
use crate::pxar::tools::{assert_relative_path, perms_from_metadata};
|
||||
use crate::pxar::tools::{assert_single_path_component, perms_from_metadata};
|
||||
|
||||
pub struct PxarDir {
|
||||
file_name: OsString,
|
||||
@ -95,7 +95,7 @@ impl PxarDirStack {
|
||||
}
|
||||
|
||||
pub fn push(&mut self, file_name: OsString, metadata: Metadata) -> Result<(), Error> {
|
||||
assert_relative_path(&file_name)?;
|
||||
assert_single_path_component(&file_name)?;
|
||||
self.path.push(&file_name);
|
||||
self.dirs.push(PxarDir::new(file_name, metadata));
|
||||
Ok(())
|
||||
|
@ -24,11 +24,22 @@ pub fn assert_relative_path<S: AsRef<OsStr> + ?Sized>(path: &S) -> Result<(), Er
|
||||
assert_relative_path_do(Path::new(path))
|
||||
}
|
||||
|
||||
/// Make sure path is a single component and not '.' or '..'.
|
||||
pub fn assert_single_path_component<S: AsRef<OsStr> + ?Sized>(path: &S) -> Result<(), Error> {
|
||||
assert_single_path_component_do(Path::new(path))
|
||||
}
|
||||
|
||||
fn assert_relative_path_do(path: &Path) -> Result<(), Error> {
|
||||
if !path.is_relative() {
|
||||
bail!("bad absolute file name in archive: {:?}", path);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn assert_single_path_component_do(path: &Path) -> Result<(), Error> {
|
||||
assert_relative_path_do(path)?;
|
||||
|
||||
let mut components = path.components();
|
||||
match components.next() {
|
||||
Some(std::path::Component::Normal(_)) => (),
|
||||
|
Loading…
Reference in New Issue
Block a user