"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
gotd and got {fetch,send,clone}: reject sha256 repos
To:
gameoftrees@openbsd.org
Date:
Thu, 01 Aug 2024 17:58:32 +0200

Download raw body.

Thread
the network code is not ready for sha256 so better error out early
rather than hit some abort() when we detect an hash algorithm mismatch.


% got fetch
Connecting to "origin" ssh://got@omarpolo.com/testing.git
got: can only fetch in SHA1 repositories: feature not implemented
% got send
Connecting to "origin" ssh://got@omarpolo.com/testing.git
got: can only send in SHA1 repositories: feature not implemented


ok?


diff -s /home/op/w/got
commit - 97a5562eda72dda8e44143130bff158b82690aee
path + /home/op/w/got (staged changes)
blob - 67c89a7abe4949fa112ddc68388c7ac88006368e
blob + ecf5c13465c733f1b15f43a289d8822cac9836a7
--- gotd/repo_read.c
+++ gotd/repo_read.c
@@ -887,6 +887,11 @@ repo_read_main(const char *title, const char *repo_pat
 		    "bare git repository required");
 		goto done;
 	}
+	if (got_repo_get_object_format(repo_read.repo) != GOT_HASH_SHA1) {
+		err = got_error_msg(GOT_ERR_NOT_IMPL,
+		    "SHA1 repository required");
+		goto done;
+	}
 
 	got_repo_temp_fds_set(repo_read.repo, temp_fds);
 
blob - 979d980b5f2f473086fcf0fbb3cf6c3715d21692
blob + e1a92b2b4829477f87e6e0b0abdf2ce6f180ff97
--- gotd/repo_write.c
+++ gotd/repo_write.c
@@ -2418,6 +2418,11 @@ repo_write_main(const char *title, const char *repo_pa
 		    "bare git repository required");
 		goto done;
 	}
+	if (got_repo_get_object_format(repo_write.repo) != GOT_HASH_SHA1) {
+		err = got_error_msg(GOT_ERR_NOT_IMPL,
+		    "SHA1 repository required");
+		goto done;
+	}
 
 	got_repo_temp_fds_set(repo_write.repo, temp_fds);
 
blob - 772c35e98bb5ed0874ea08d5d0d4437001a7480e
blob + f7c6c95109c85499d11ea720c34db5ea698f7888
--- gotd/session_read.c
+++ gotd/session_read.c
@@ -853,6 +853,11 @@ session_read_main(const char *title, const char *repo_
 		    "bare git repository required");
 		goto done;
 	}
+	if (got_repo_get_object_format(gotd_session.repo) != GOT_HASH_SHA1) {
+		err = got_error_msg(GOT_ERR_NOT_IMPL,
+		    "SHA1 repository required");
+		goto done;
+	}
 
 	got_repo_temp_fds_set(gotd_session.repo, temp_fds);
 
blob - 3e379f9e08e2cc6c3649d68f36f5aff4245910dc
blob + 341bf6f37a650de788b69ab7ace45d4969e8a5ac
--- gotd/session_write.c
+++ gotd/session_write.c
@@ -1702,6 +1702,11 @@ session_write_main(const char *title, const char *repo
 		    "bare git repository required");
 		goto done;
 	}
+	if (got_repo_get_object_format(gotd_session.repo) != GOT_HASH_SHA1) {
+		err = got_error_msg(GOT_ERR_NOT_IMPL,
+		    "SHA1 repository required");
+		goto done;
+	}
 
 	got_repo_temp_fds_set(gotd_session.repo, temp_fds);
 
blob - ba7667f6986fa052b7c6f36d5d7ff65c5a87bff8
blob + 0f2262b3bd4148f5010fb425721493915d2f22b7
--- lib/fetch.c
+++ lib/fetch.c
@@ -136,6 +136,10 @@ got_fetch_pack(struct got_object_id **pack_hash, struc
 
 	*pack_hash = NULL;
 
+	if (repo && got_repo_get_object_format(repo) != GOT_HASH_SHA1)
+		return got_error_fmt(GOT_ERR_NOT_IMPL,
+		    "can only fetch in SHA1 repositories");
+
 	/*
 	 * Prevent fetching of references that won't make any
 	 * sense outside of the remote repository's context.
blob - a1473da8306f07e7f95614c32166941e804ca5f1
blob + 56be68da0423b0a748c25bd11d1c3aeaa13227e1
--- lib/send.c
+++ lib/send.c
@@ -364,6 +364,10 @@ got_send_pack(const char *remote_name, struct got_path
 	TAILQ_INIT(&have_refs);
 	TAILQ_INIT(&their_refs);
 
+	if (got_repo_get_object_format(repo) != GOT_HASH_SHA1)
+		return got_error_fmt(GOT_ERR_NOT_IMPL,
+		    "can only send in SHA1 repositories");
+
 	TAILQ_FOREACH(pe, branch_names, entry) {
 		const char *branchname = pe->path;
 		const char *targetname = pe->data;