prevent using invalid group names

This commit is contained in:
steven-omaha
2023-02-27 15:01:44 +01:00
parent 92650b0182
commit 55c23d1953
+12 -3
View File
@@ -307,6 +307,18 @@ impl Pacdef {
.context("getting groups from args")?
.collect();
// prevent group names that resolve to directories
for name in &new_group_names {
ensure!(
*name != ".",
crate::Error::InvalidGroupName(".".to_string())
);
ensure!(
*name != "..",
crate::Error::InvalidGroupName("..".to_string())
);
}
let paths: Vec<_> = new_group_names
.into_iter()
.map(|name| {
@@ -317,9 +329,6 @@ impl Pacdef {
.collect();
for file in &paths {
file.file_name()
.ok_or_else(|| crate::Error::InvalidGroupName("..".to_string()))?;
ensure!(
!file.exists(),
crate::Error::GroupAlreadyExists(file.clone())