Skip to content

Commit 8430b43

Browse files
vdyegitster
authored andcommitted
submodule-config.c: strengthen URL fsck check
Update the validation of "curl URL" submodule URLs (i.e. those that specify an "http[s]" or "ftp[s]" protocol) in 'check_submodule_url()' to catch more invalid URLs. The existing validation using 'credential_from_url_gently()' parses certain URLs incorrectly, leading to invalid submodule URLs passing 'git fsck' checks. Conversely, 'url_normalize()' - used to validate remote URLs in 'remote_get()' - correctly identifies the invalid URLs missed by 'credential_from_url_gently()'. To catch more invalid cases, replace 'credential_from_url_gently()' with 'url_normalize()' followed by a 'url_decode()' and a check for newlines (mirroring 'check_url_component()' in the 'credential_from_url_gently()' validation). Signed-off-by: Victoria Dye <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e2fc39 commit 8430b43

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

submodule-config.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "thread-utils.h"
1616
#include "tree-walk.h"
1717
#include "url.h"
18-
#include "credential.h"
18+
#include "urlmatch.h"
1919

2020
/*
2121
* submodule cache lookup structure
@@ -350,12 +350,18 @@ int check_submodule_url(const char *url)
350350
}
351351

352352
else if (url_to_curl_url(url, &curl_url)) {
353-
struct credential c = CREDENTIAL_INIT;
354353
int ret = 0;
355-
if (credential_from_url_gently(&c, curl_url, 1) ||
356-
!*c.host)
354+
char *normalized = url_normalize(curl_url, NULL);
355+
if (normalized) {
356+
char *decoded = url_decode(normalized);
357+
if (strchr(decoded, '\n'))
358+
ret = -1;
359+
free(normalized);
360+
free(decoded);
361+
} else {
357362
ret = -1;
358-
credential_clear(&c);
363+
}
364+
359365
return ret;
360366
}
361367

t/t7450-bad-git-dotfiles.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,14 @@ test_expect_success 'check urls' '
6363
./%0ahost=example.com/foo.git
6464
https://one.example.com/evil?%0ahost=two.example.com
6565
https:///example.com/foo.git
66+
http://example.com:test/foo.git
6667
https::example.com/foo.git
6768
http:::example.com/foo.git
6869
EOF
6970
7071
test_cmp expect actual
7172
'
7273

73-
# NEEDSWORK: the URL checked here is not valid (and will not work as a remote if
74-
# a user attempts to clone it), but the fsck check passes.
75-
test_expect_failure 'url check misses invalid cases' '
76-
test-tool submodule check-url >actual <<-\EOF &&
77-
http://example.com:test/foo.git
78-
EOF
79-
80-
test_must_be_empty actual
81-
'
82-
8374
test_expect_success 'create innocent subrepo' '
8475
git init innocent &&
8576
git -C innocent commit --allow-empty -m foo

0 commit comments

Comments
 (0)