Skip to content

Commit b889953

Browse files
committed
don't allow object hashes in excludes (#450)
1 parent 79e0eaf commit b889953

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

git-refspec/src/parse.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub enum Error {
66
NegativeWithDestination,
77
#[error("Negative specs must not be empty")]
88
NegativeEmpty,
9+
#[error("Negative specs must be object hashes")]
10+
NegativeObjectHash,
911
#[error("Cannot push into an empty destination")]
1012
PushToEmpty,
1113
#[error("glob patterns may only involved a single '*' character, found {pattern:?}")]
@@ -88,8 +90,17 @@ pub(crate) mod function {
8890
}
8991
};
9092

91-
if mode == Mode::Negative && src.is_none() {
92-
return Err(Error::NegativeEmpty);
93+
if mode == Mode::Negative {
94+
match src {
95+
Some(spec) => {
96+
if spec.len() >= git_hash::Kind::shortest().len_in_hex()
97+
&& spec.iter().all(|b| b.is_ascii_hexdigit())
98+
{
99+
return Err(Error::NegativeObjectHash);
100+
}
101+
}
102+
None => return Err(Error::NegativeEmpty),
103+
}
93104
}
94105

95106
if let Some(spec) = src.as_mut() {

git-refspec/tests/parse/invalid.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ fn negative_must_not_be_empty() {
1313
}
1414
}
1515

16+
#[test]
17+
fn negative_must_not_be_object_hash() {
18+
for op in [Operation::Fetch, Operation::Push] {
19+
assert!(matches!(
20+
try_parse("^e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", op).unwrap_err(),
21+
Error::NegativeObjectHash
22+
));
23+
}
24+
}
25+
1626
#[test]
1727
fn negative_with_destination() {
1828
for op in [Operation::Fetch, Operation::Push] {

0 commit comments

Comments
 (0)