From: Thomas Bachem via GitGitGadget Date: Sat, 07 Nov 2026 08:42:36 GMT Subject: [PATCH 04/15] bundle-uri: handle NULL value for fetch.bundleCreationToken Message-ID: <4eb7085084b880f90705799d523ab554fd1cabd3.1794040968.git.gitgitgadget@gmail.com> In-Reply-To: From: Thomas Bachem 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 --- 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 2bb2eb99e4..7de17634cf 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