Skip to content

Commit 0472422

Browse files
peffgitster
authored andcommitted
test-dump-cache-tree: avoid overflow of cache-tree name
When dumping a cache-tree, we sprintf sub-tree names directly into a fixed-size buffer, which can overflow. We can trivially fix this by converting to xsnprintf to at least notice and die. This probably should handle arbitrary-sized names, but there's not much point. It's used only by the test scripts, so the trivial fix is enough. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3131977 commit 0472422

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

test-dump-cache-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int dump_cache_tree(struct cache_tree *it,
4747
struct cache_tree_sub *rdwn;
4848

4949
rdwn = cache_tree_sub(ref, down->name);
50-
sprintf(path, "%s%.*s/", pfx, down->namelen, down->name);
50+
xsnprintf(path, sizeof(path), "%s%.*s/", pfx, down->namelen, down->name);
5151
if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
5252
errs = 1;
5353
}

0 commit comments

Comments
 (0)