Skip to content

Commit 8373408

Browse files
committed
Merge branch 'kj/refspec-parsing-outside-repository' into jch
"git ls-remote '+refs/tags/*:refs/tags/*' https://..." run outside a repository would dereference a NULL while trying to see if the given refspec is a single-object refspec, which has been corrected. * kj/refspec-parsing-outside-repository: refspec: fix typo in comment refspec: safely parse refspecs outside a repository
2 parents 17766d5 + eb50581 commit 8373408

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

refspec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
8484
*/
8585
if (!*item->src)
8686
return 0; /* negative refspecs must not be empty */
87-
else if (llen == the_hash_algo->hexsz && !get_oid_hex(item->src, &unused))
88-
return 0; /* negative refpsecs cannot be exact sha1 */
87+
else if (the_hash_algo && llen == the_hash_algo->hexsz && !get_oid_hex(item->src, &unused))
88+
return 0; /* negative refspecs cannot be exact sha1 */
8989
else if (!check_refname_format(item->src, flags))
9090
; /* valid looking ref is ok */
9191
else
@@ -101,7 +101,7 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
101101
/* LHS */
102102
if (!*item->src)
103103
; /* empty is ok; it means "HEAD" */
104-
else if (llen == the_hash_algo->hexsz && !get_oid_hex(item->src, &unused))
104+
else if (the_hash_algo && llen == the_hash_algo->hexsz && !get_oid_hex(item->src, &unused))
105105
item->exact_sha1 = 1; /* ok */
106106
else if (!check_refname_format(item->src, flags))
107107
; /* valid looking ref is ok */

t/t5551-http-fetch-smart.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,4 +782,11 @@ test_expect_success 'tag following always works over v0 http' '
782782
test_cmp expect actual
783783
'
784784

785+
test_expect_success 'ls-remote outside repo does not segfault with fetch refspec' '
786+
nongit git \
787+
-c remote.origin.url="$HTTPD_URL/smart/repo.git" \
788+
-c remote.origin.fetch=anything \
789+
ls-remote origin
790+
'
791+
785792
test_done

0 commit comments

Comments
 (0)