File 0001-Clear-data-after-negotiation.patch of Package libgit2

From d6392feb57909d110517df7f818b96268ae29743 Mon Sep 17 00:00:00 2001
From: lmcglash <lmcglash@mathworks.com>
Date: Mon, 25 Nov 2024 21:55:43 +0000
Subject: [PATCH] Clear data after negotiation
References: bsc#1246578

Cherry-picked from eb84531575d8 (Clear data after negotiation)

[js] GIT_SSH_MEMORY_CREDENTIALS is still the right one in 1.7.0
---
 src/libgit2/transports/smart_protocol.c |  1 +
 tests/libgit2/online/clone.c            | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/src/libgit2/transports/smart_protocol.c b/src/libgit2/transports/smart_protocol.c
index c9c422d4c85c..b98363c2568d 100644
--- a/src/libgit2/transports/smart_protocol.c
+++ b/src/libgit2/transports/smart_protocol.c
@@ -426,6 +426,7 @@ int git_smart__negotiate_fetch(
 
 		if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0)
 			goto on_error;
+		git_str_clear(&data);
 
 		while ((error = recv_pkt((git_pkt **)&pkt, NULL, t)) == 0) {
 			bool complete = false;
diff --git a/tests/libgit2/online/clone.c b/tests/libgit2/online/clone.c
index 5789e9654c3d..5d4e9324da3e 100644
--- a/tests/libgit2/online/clone.c
+++ b/tests/libgit2/online/clone.c
@@ -649,6 +649,24 @@ void test_online_clone__ssh_github(void)
 	cl_git_pass(git_clone(&g_repo, SSH_REPO_URL, "./foo", &g_options));
 }
 
+void test_online_clone__ssh_github_shallow(void)
+{
+#if !defined(GIT_SSH) || !defined(GIT_SSH_MEMORY_CREDENTIALS)
+	clar__skip();
+#endif
+
+	if (!_github_ssh_pubkey || !_github_ssh_privkey)
+		clar__skip();
+
+	cl_fake_homedir(NULL);
+
+	g_options.fetch_opts.callbacks.credentials = github_credentials;
+	g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check;
+	g_options.fetch_opts.depth = 1;
+
+	cl_git_pass(git_clone(&g_repo, SSH_REPO_URL, "./foo", &g_options));
+}
+
 void test_online_clone__ssh_auth_methods(void)
 {
 	int with_user;
-- 
2.50.0

openSUSE Build Service is sponsored by