Skip to content

Commit a4801fe

Browse files
committed
fix: assure valid path components are never plain . or ...
1 parent a74a861 commit a4801fe

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: gix-validate/src/path.rs

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub mod component {
2020
DotGitDir,
2121
#[error("The .gitmodules file must not be a symlink")]
2222
SymlinkedGitModules,
23+
#[error("Relative components '.' and '..' are disallowed")]
24+
Relative,
2325
}
2426

2527
/// Further specify what to check for in [`component()`](super::component())
@@ -78,6 +80,9 @@ pub fn component(
7880
if input.is_empty() {
7981
return Err(component::Error::Empty);
8082
}
83+
if input == ".." || input == "." {
84+
return Err(component::Error::Relative);
85+
}
8186
if protect_windows {
8287
if input.find_byteset(br"/\").is_some() {
8388
return Err(component::Error::PathSeparator);

Diff for: gix-validate/tests/path/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ mod component {
253253
mktest!(con_with_extension, b"CON.abc", Error::WindowsReservedName);
254254
mktest!(con_with_middle, b"CON.tar.xz", Error::WindowsReservedName);
255255
mktest!(con_mixed_with_middle, b"coN.tar.xz ", Error::WindowsReservedName);
256+
mktest!(dot_dot, b"..", Error::Relative);
257+
mktest!(dot_dot_no_opts, b"..", Error::Relative, NO_OPTS);
258+
mktest!(single_dot, b".", Error::Relative);
259+
mktest!(single_dot_no_opts, b".", Error::Relative, NO_OPTS);
256260
mktest!(
257261
conout_mixed_with_extension,
258262
b"ConOut$ .xyz",

0 commit comments

Comments
 (0)