[JGIT PATCH 3/8] Refuse to create or delete funny ref names over dumb transports

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Shawn O. Pearce
Date: Monday, June 30, 2008 - 8:04 pm

If the RemoteRefUpdate requests us to create a remote name of just
"master" (say due to a bug in the push command line tool) we would do
just that, creating "$project.git/master" on the remote side.  This is
not a valid ref for Git and confusion ensues when C Git tries to
operate on the same repository.

Normally these sorts of bad refs are blocked by git-receive-pack
on the remote side, but here we don't have that so we must do the
blocking as part of the push connection.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../spearce/jgit/transport/WalkPushConnection.java |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/WalkPushConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/WalkPushConnection.java
index 5450b84..e11b85a 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/WalkPushConnection.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/WalkPushConnection.java
@@ -129,6 +129,13 @@ class WalkPushConnection extends BaseConnection implements PushConnection {
 		//
 		final List<RemoteRefUpdate> updates = new ArrayList<RemoteRefUpdate>();
 		for (final RemoteRefUpdate u : refUpdates.values()) {
+			final String n = u.getRemoteName();
+			if (!n.startsWith("refs/") || !Repository.isValidRefName(n)) {
+				u.setStatus(Status.REJECTED_OTHER_REASON);
+				u.setMessage("funny refname");
+				continue;
+			}
+
 			if (AnyObjectId.equals(ObjectId.zeroId(), u.getNewObjectId()))
 				deleteCommand(u);
 			else
-- 
1.5.6.74.g8a5e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[JGIT PATCH 3/8] Refuse to create or delete funny ref name ..., Shawn O. Pearce, (Mon Jun 30, 8:04 pm)