From 8b834a7b6e1b18c0ad7a2afba0acb6c20ae43c5f Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 20 Oct 2022 12:59:55 +0200 Subject: [PATCH] Protect ourselves against naked refs Signed-off-by: Alexis Sellier --- radicle/src/storage/git.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index 5b2a87c6..ac617e0f 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -604,13 +604,15 @@ impl WriteRepository for Repository { callbacks.update_tips(|name, old, new| { if let Ok(name) = git::RefString::try_from(name) { - updates.push(RefUpdate::from(name, old, new)); - } else { - log::warn!("Invalid ref `{}` detected; aborting fetch", name); - return false; + if name.to_namespaced().is_some() { + updates.push(RefUpdate::from(name, old, new)); + // Returning `true` ensures the process is not aborted. + return true; + } } - // Returning `true` ensures the process is not aborted. - true + log::warn!("Invalid ref `{}` detected; aborting fetch", name); + + false }); { @@ -813,6 +815,15 @@ mod tests { assert_eq!(alice_oid.target(), bob_oid.target()); } + + // Canonical HEAD is set correctly. + let alice_repo = alice.repository(proj).unwrap(); + let bob_repo = bob.repository(proj).unwrap(); + + assert_eq!( + bob_repo.backend.head().unwrap().target().unwrap(), + alice_repo.backend.head().unwrap().target().unwrap() + ); } #[test]