Skip to content

Commit 83befd3

Browse files
jacobvosmaergitster
authored andcommitted
ls-refs.c: initialize 'prefixes' before using it
Correctly initialize the "prefixes" strvec using strvec_init() instead of simply zeroing it via the earlier memset(). There's no way to trigger a crash, since the first 'ref-prefix' command will initialize the strvec via the 'ALLOC_GROW' in 'strvec_push_nodup()' (the alloc and nr variables are already zero'd, so the call to ALLOC_GROW is valid). If no "ref-prefix" command was given, then the call to 'ls-refs.c:ref_match()' will abort early after it reads the zero in 'prefixes->nr'. Likewise, strvec_clear() will only call free() on the array, which is NULL, so we're safe there, too. But, all of this is dangerous and requires more reasoning than it would if we simply called 'strvec_init()', so do that. Signed-off-by: Jacob Vosmaer <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16b1985 commit 83befd3

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

ls-refs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ int ls_refs(struct repository *r, struct strvec *keys,
9090
struct ls_refs_data data;
9191

9292
memset(&data, 0, sizeof(data));
93+
strvec_init(&data.prefixes);
9394

9495
git_config(ls_refs_config, NULL);
9596

0 commit comments

Comments
 (0)