Skip to content

Commit 4dc3e23

Browse files
committed
bundle-uri: avoid using undefined output of sscanf()
In c429bed (bundle-uri: store fetch.bundleCreationToken, 2023-01-31) code was introduced that assumes that an `sscanf()` call leaves its output variables unchanged unless the return value indicates success. However, the POSIX documentation makes no such guarantee: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sscanf.html So let's make sure that the output variable `maxCreationToken` is always well-defined. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 077bcab commit 4dc3e23

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

bundle-uri.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,13 @@ static int fetch_bundles_by_token(struct repository *r,
532532
*/
533533
if (!repo_config_get_value(r,
534534
"fetch.bundlecreationtoken",
535-
&creationTokenStr) &&
536-
sscanf(creationTokenStr, "%"PRIu64, &maxCreationToken) == 1 &&
537-
bundles.items[0]->creationToken <= maxCreationToken) {
538-
free(bundles.items);
539-
return 0;
535+
&creationTokenStr)) {
536+
if (sscanf(creationTokenStr, "%"PRIu64, &maxCreationToken) != 1)
537+
maxCreationToken = 0;
538+
if (bundles.items[0]->creationToken <= maxCreationToken) {
539+
free(bundles.items);
540+
return 0;
541+
}
540542
}
541543

542544
/*

0 commit comments

Comments
 (0)