[PATCH v3 14/15] bundle-uri: handle NULL values in bundle lists
- From
Thomas Bachem via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Nov 11, 2026, 22:49 UTC
- Message-ID
- <474aebd572dad8af4820fe5ac13d9c22ec3ac9fd.1794437355.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2297.v3.git.1794437355.gitgitgadget@gmail.com>
From: Thomas Bachem <mail@thomasbachem.com>
A bundle list that gives bundle.mode, bundle.heuristic, bundle.<id>.uri or bundle.<id>.creationToken without a value makes "git clone --bundle-uri" and "git fetch" segfault: bundle_list_update() passes the NULL value to strcmp(), relative_url() or sscanf(). Such a list can also come from a server, through a bundle URI that it advertises.
Reject a missing value with config_error_nonbool(). That makes the list invalid, as an unknown mode or a second uri already does, and the clone or fetch goes on without the bundles.
Assisted-by: Claude Opus 5.5 Signed-off-by: Thomas Bachem <mail@thomasbachem.com> --- bundle-uri.c | 9 +++++++++ t/t5750-bundle-uri-parse.sh | 16 ++++++++++++++++ 2 files changed, 25 insertions(+)
diff --git a/bundle-uri.c b/bundle-uri.c index 67a717e857..41c817eefb 100644 --- a/bundle-uri.c +++ b/bundle-uri.c @@ -164,6 +164,8 @@ static int bundle_list_update(const char *key, const char *value, } if (!strcmp(subkey, "mode")) { + if (!value) + return config_error_nonbool(key); if (!strcmp(value, "all")) list->mode = BUNDLE_MODE_ALL; else if (!strcmp(value, "any")) @@ -175,6 +177,9 @@ static int bundle_list_update(const char *key, const char *value, if (!strcmp(subkey, "heuristic")) { int i; + + if (!value) + return config_error_nonbool(key); for (i = 0; i < BUNDLE_HEURISTIC__COUNT; i++) { if (heuristics[i].heuristic && heuristics[i].name && @@ -209,6 +214,8 @@ static int bundle_list_update(const char *key, const char *value, strbuf_release(&id); if (!strcmp(subkey, "uri")) { + if (!value) + return config_error_nonbool(key); if (bundle->uri) return -1; bundle->uri = relative_url(list->baseURI, value, NULL); @@ -216,6 +223,8 @@ static int bundle_list_update(const char *key, const char *value, } if (!strcmp(subkey, "creationtoken")) { + if (!value) + return config_error_nonbool(key); if (sscanf(value, "%"PRIu64, &bundle->creationToken) != 1) warning(_("could not parse bundle list key %s with value '%s'"), "creationToken", value); diff --git a/t/t5750-bundle-uri-parse.sh b/t/t5750-bundle-uri-parse.sh index 70ae94c4d0..a91c1b428d 100755 --- a/t/t5750-bundle-uri-parse.sh +++ b/t/t5750-bundle-uri-parse.sh @@ -312,4 +312,20 @@ test_expect_success 'parse config format: bundle with url instead of uri' ' test_grep "bundle '\''typo'\'' has no uri" err ' +test_expect_success 'parse config format edge cases: keys without a value' ' + for key in mode heuristic + do + printf "[bundle]\n\tversion = 1\n\t%s\n" "$key" >input && + test_must_fail test-tool bundle-uri parse-config input 2>err && + test_grep "missing value for .bundle.$key." err || return 1 + done && + for key in uri creationtoken + do + printf "[bundle]\n\tversion = 1\n\tmode = all\n[bundle \"one\"]\n\t%s\n" \ + "$key" >input && + test_must_fail test-tool bundle-uri parse-config input 2>err && + test_grep "missing value for .bundle.one.$key." err || return 1 + done +' + test_done
-- gitgitgadget