Skip to content

Commit ee89941

Browse files
committed
Merge remote-tracking branch 'upstream/maint/v0.25'
2 parents 5afd0f9 + 2fcb870 commit ee89941

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed

src/transports/http.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,13 +624,12 @@ static int http_connect(http_subtransport *t)
624624
if ((!error || error == GIT_ECERTIFICATE) && t->owner->certificate_check_cb != NULL &&
625625
git_stream_is_encrypted(t->io)) {
626626
git_cert *cert;
627-
int is_valid;
627+
int is_valid = (error == GIT_OK);
628628

629629
if ((error = git_stream_certificate(&cert, t->io)) < 0)
630630
return error;
631631

632632
giterr_clear();
633-
is_valid = error != GIT_ECERTIFICATE;
634633
error = t->owner->certificate_check_cb(cert, is_valid, t->connection_data.host, t->owner->message_cb_payload);
635634

636635
if (error < 0) {

src/transports/smart_pkt.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,23 @@ int git_pkt_parse_line(
427427
if (bufflen > 0 && bufflen < (size_t)len)
428428
return GIT_EBUFS;
429429

430+
/*
431+
* The length has to be exactly 0 in case of a flush
432+
* packet or greater than PKT_LEN_SIZE, as the decoded
433+
* length includes its own encoded length of four bytes.
434+
*/
435+
if (len != 0 && len < PKT_LEN_SIZE)
436+
return GIT_ERROR;
437+
430438
line += PKT_LEN_SIZE;
431439
/*
432-
* TODO: How do we deal with empty lines? Try again? with the next
433-
* line?
440+
* The Git protocol does not specify empty lines as part
441+
* of the protocol. Not knowing what to do with an empty
442+
* line, we should return an error upon hitting one.
434443
*/
435444
if (len == PKT_LEN_SIZE) {
436-
*head = NULL;
437-
*out = line;
438-
return 0;
445+
giterr_set_str(GITERR_NET, "Invalid empty packet");
446+
return GIT_ERROR;
439447
}
440448

441449
if (len == 0) { /* Flush pkt */

src/transports/smart_protocol.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,6 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
763763
line_len -= (line_end - line);
764764
line = line_end;
765765

766-
/* When a valid packet with no content has been
767-
* read, git_pkt_parse_line does not report an
768-
* error, but the pkt pointer has not been set.
769-
* Handle this by skipping over empty packets.
770-
*/
771-
if (pkt == NULL)
772-
continue;
773-
774766
error = add_push_report_pkt(push, pkt);
775767

776768
git_pkt_free(pkt);
@@ -825,9 +817,6 @@ static int parse_report(transport_smart *transport, git_push *push)
825817

826818
error = 0;
827819

828-
if (pkt == NULL)
829-
continue;
830-
831820
switch (pkt->type) {
832821
case GIT_PKT_DATA:
833822
/* This is a sideband packet which contains other packets */

tests/online/badssl.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,71 @@ static bool g_has_ssl = true;
1010
static bool g_has_ssl = false;
1111
#endif
1212

13+
static int cert_check_assert_invalid(git_cert *cert, int valid, const char* host, void *payload)
14+
{
15+
GIT_UNUSED(cert); GIT_UNUSED(host); GIT_UNUSED(payload);
16+
17+
cl_assert_equal_i(0, valid);
18+
19+
return GIT_ECERTIFICATE;
20+
}
21+
1322
void test_online_badssl__expired(void)
1423
{
24+
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
25+
opts.fetch_opts.callbacks.certificate_check = cert_check_assert_invalid;
26+
1527
if (!g_has_ssl)
1628
cl_skip();
1729

1830
cl_git_fail_with(GIT_ECERTIFICATE,
1931
git_clone(&g_repo, "https://expired.badssl.com/fake.git", "./fake", NULL));
32+
33+
cl_git_fail_with(GIT_ECERTIFICATE,
34+
git_clone(&g_repo, "https://expired.badssl.com/fake.git", "./fake", &opts));
2035
}
2136

2237
void test_online_badssl__wrong_host(void)
2338
{
39+
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
40+
opts.fetch_opts.callbacks.certificate_check = cert_check_assert_invalid;
41+
2442
if (!g_has_ssl)
2543
cl_skip();
2644

2745
cl_git_fail_with(GIT_ECERTIFICATE,
2846
git_clone(&g_repo, "https://wrong.host.badssl.com/fake.git", "./fake", NULL));
47+
cl_git_fail_with(GIT_ECERTIFICATE,
48+
git_clone(&g_repo, "https://wrong.host.badssl.com/fake.git", "./fake", &opts));
2949
}
3050

3151
void test_online_badssl__self_signed(void)
3252
{
53+
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
54+
opts.fetch_opts.callbacks.certificate_check = cert_check_assert_invalid;
55+
3356
if (!g_has_ssl)
3457
cl_skip();
3558

3659
cl_git_fail_with(GIT_ECERTIFICATE,
3760
git_clone(&g_repo, "https://self-signed.badssl.com/fake.git", "./fake", NULL));
61+
cl_git_fail_with(GIT_ECERTIFICATE,
62+
git_clone(&g_repo, "https://self-signed.badssl.com/fake.git", "./fake", &opts));
3863
}
3964

4065
void test_online_badssl__old_cipher(void)
4166
{
67+
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
68+
opts.fetch_opts.callbacks.certificate_check = cert_check_assert_invalid;
69+
70+
/* FIXME: we don't actually reject RC4 anywhere, figure out what to tweak */
71+
cl_skip();
72+
4273
if (!g_has_ssl)
4374
cl_skip();
4475

45-
cl_git_fail(git_clone(&g_repo, "https://rc4.badssl.com/fake.git", "./fake", NULL));
76+
cl_git_fail_with(GIT_ECERTIFICATE,
77+
git_clone(&g_repo, "https://rc4.badssl.com/fake.git", "./fake", NULL));
78+
cl_git_fail_with(GIT_ECERTIFICATE,
79+
git_clone(&g_repo, "https://rc4.badssl.com/fake.git", "./fake", &opts));
4680
}

0 commit comments

Comments
 (0)