]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bundle-uri: validate that bundle entries have a uri
authorSam Bostock <sam.bostock@shopify.com>
Fri, 19 Dec 2025 16:01:46 +0000 (16:01 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 Dec 2025 05:45:27 +0000 (14:45 +0900)
When a bundle list config file has a typo like 'url' instead of 'uri',
or simply omits the uri field, the bundle entry is created but
bundle->uri remains NULL. This causes a segfault when copy_uri_to_file()
passes the NULL to starts_with().

Signed-off-by: Sam Bostock <sam@sambostock.ca>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bundle-uri.c
t/t5750-bundle-uri-parse.sh

index 57cccfc6b8ee1fe95e1d4b6e239336d6ad8f9049..3b2e347288c3b73a5e1aad63154ba754e3c0b833 100644 (file)
@@ -89,7 +89,10 @@ static int summarize_bundle(struct remote_bundle_info *info, void *data)
 {
        FILE *fp = data;
        fprintf(fp, "[bundle \"%s\"]\n", info->id);
-       fprintf(fp, "\turi = %s\n", info->uri);
+       if (info->uri)
+               fprintf(fp, "\turi = %s\n", info->uri);
+       else
+               fprintf(fp, "\t# uri = (missing)\n");
 
        if (info->creationToken)
                fprintf(fp, "\tcreationToken = %"PRIu64"\n", info->creationToken);
@@ -267,6 +270,19 @@ int bundle_uri_parse_config_format(const char *uri,
                result = 1;
        }
 
+       if (!result) {
+               struct hashmap_iter iter;
+               struct remote_bundle_info *bundle;
+
+               hashmap_for_each_entry(&list->bundles, &iter, bundle, ent) {
+                       if (!bundle->uri) {
+                               error(_("bundle list at '%s': bundle '%s' has no uri"),
+                                     uri, bundle->id ? bundle->id : "<unknown>");
+                               result = 1;
+                       }
+               }
+       }
+
        return result;
 }
 
@@ -751,6 +767,12 @@ static int fetch_bundle_uri_internal(struct repository *r,
                return -1;
        }
 
+       if (!bundle->uri) {
+               error(_("bundle '%s' has no uri"),
+                     bundle->id ? bundle->id : "<unknown>");
+               return -1;
+       }
+
        if (!bundle->file &&
            !(bundle->file = find_temp_filename())) {
                result = -1;
index 80a3f83ffb7e601db2799d3290e115551e11aa32..294f9d9c6455d4374db57ee8fe139ebd3ef6a9fc 100755 (executable)
@@ -286,4 +286,30 @@ test_expect_success 'parse config format edge cases: creationToken heuristic' '
        grep "could not parse bundle list key creationToken with value '\''bogus'\''" err
 '
 
+test_expect_success 'parse config format: bundle with missing uri' '
+       cat >input <<-\EOF &&
+       [bundle]
+               version = 1
+               mode = all
+       [bundle "missing-uri"]
+               creationToken = 1
+       EOF
+
+       test_must_fail test-tool bundle-uri parse-config input 2>err &&
+       grep "bundle '\''missing-uri'\'' has no uri" err
+'
+
+test_expect_success 'parse config format: bundle with url instead of uri' '
+       cat >input <<-\EOF &&
+       [bundle]
+               version = 1
+               mode = all
+       [bundle "typo"]
+               url = https://example.com/bundle.bdl
+       EOF
+
+       test_must_fail test-tool bundle-uri parse-config input 2>err &&
+       grep "bundle '\''typo'\'' has no uri" err
+'
+
 test_done