[PATCH v2 04/15] bundle-uri: handle NULL value for fetch.bundleCreationToken
- From
Thomas Bachem via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Nov 10, 2026, 07:36 UTC
- Message-ID
- <a822cbb84431c3bd5e093ec7d94dfdd6b17b1f96.1794296205.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2297.v2.git.1794296205.gitgitgadget@gmail.com>
From: Thomas Bachem <mail@thomasbachem.com>
A fetch.bundleCreationToken without a value makes "git fetch" and "git clone --bundle-uri" segfault when the bundle list uses the creationToken heuristic: fetch_bundles_by_token() passes the NULL value to sscanf().
The function already treats a token that does not parse as 0, as if no bundles had been fetched before, so it downloads them and then stores the new token. Treat a missing value the same way.
Assisted-by: Claude Fable 5.1 Signed-off-by: Thomas Bachem <mail@thomasbachem.com> --- bundle-uri.c | 3 ++- t/t5558-clone-bundle-uri.sh | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/bundle-uri.c b/bundle-uri.c index 9797eaed9a..67a717e857 100644 --- a/bundle-uri.c +++ b/bundle-uri.c @@ -572,7 +572,8 @@ static int fetch_bundles_by_token(struct repository *r, if (!repo_config_get_value(r, "fetch.bundlecreationtoken", &creationTokenStr)) { - if (sscanf(creationTokenStr, "%"PRIu64, &maxCreationToken) != 1) + if (!creationTokenStr || + sscanf(creationTokenStr, "%"PRIu64, &maxCreationToken) != 1) maxCreationToken = 0; if (bundles.items[0]->creationToken <= maxCreationToken) { free(bundles.items); diff --git a/t/t5558-clone-bundle-uri.sh b/t/t5558-clone-bundle-uri.sh index f81f1f8db7..e86ed7d30c 100755 --- a/t/t5558-clone-bundle-uri.sh +++ b/t/t5558-clone-bundle-uri.sh @@ -346,6 +346,26 @@ test_expect_success 'clone bundle list (file, any mode, all failures)' ' test_grep ! "refs/bundles/heads/" refs ' +test_expect_success 'fetch treats fetch.bundleCreationToken without a value as 0' ' + test_when_finished "rm -rf token-without-value" && + cat >bundle-list <<-EOF && + [bundle] + version = 1 + mode = all + heuristic = creationToken + + [bundle "bundle-1"] + uri = file://$(pwd)/clone-from/bundle-1.bundle + creationToken = 1 + EOF + + git clone --no-local clone-from token-without-value && + git -C token-without-value \ + -c fetch.bundleURI="file://$(pwd)/bundle-list" \ + -c fetch.bundleCreationToken fetch origin && + test_cmp_config -C token-without-value 1 fetch.bundlecreationtoken +' + test_expect_success 'negotiation: bundle with part of wanted commits' ' test_when_finished "rm -f trace*.txt" && GIT_TRACE_PACKET="$(pwd)/trace-packet.txt" \
-- gitgitgadget