]> git.proxmox.com Git - libgit2.git/commitdiff
fetch: clear the connection data on close
authorCarlos Martín Nieto <cmn@dwim.me>
Wed, 19 Nov 2014 19:53:25 +0000 (20:53 +0100)
committerCarlos Martín Nieto <cmn@dwim.me>
Wed, 19 Nov 2014 19:57:15 +0000 (20:57 +0100)
When we fetch twice with the same remote object, we did not properly
clear the connection flags, so we would leak state from the last
connection.

This can cause the second fetch with the same remote object to fail if
using a HTTP URL where the server redirects to HTTPS, as the second
fetch would see `use_ssl` set and think the initial connection wanted to
downgrade the connection.

src/transports/http.c
tests/online/fetch.c

index 4070b683aaff987c0464a1808d6a5fdc7e29b245..234ee229f7fba2eb296b270cce0e2031a2f61430 100644 (file)
@@ -1009,6 +1009,7 @@ static int http_close(git_smart_subtransport *subtransport)
        git_vector_clear(&t->auth_contexts);
 
        gitno_connection_data_free_ptrs(&t->connection_data);
+       memset(&t->connection_data, 0x0, sizeof(gitno_connection_data));
 
        return 0;
 }
index ec16dd2fdfa64f575d75cb682ba0f4e3c7dc77bf..848b87410624c1ae6686080c9f9152c6ca87886f 100644 (file)
@@ -202,3 +202,14 @@ void test_online_fetch__remote_symrefs(void)
 
        git_remote_free(remote);
 }
+
+void test_online_fetch__twice(void)
+{
+       git_remote *remote;
+
+       cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git"));
+       cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+       cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+
+       git_remote_free(remote);
+}