Skip to content

Commit 43d20a8

Browse files
drafnelgitster
authored andcommitted
refs.c: ensure struct whose member may be passed to realloc is initialized
The variable "refs" is allocated on the stack but is not initialized. It is passed to read_packed_refs(), and its struct members may eventually be passed to add_ref() and ALLOC_GROW(). Since the structure has not been initialized, its members may contain random non-zero values. So let's initialize it. The call sequence looks something like this: resolve_gitlink_packed_ref(...) { struct cached_refs refs; ... read_packed_refs(f, &refs); ... } read_packed_refs(FILE*, struct cached_refs *cached_refs) { ... add_ref(name, sha1, flag, &cached_refs->packed, &last); ... } add_ref(..., struct ref_array *refs, struct ref_entry **) { ... ALLOC_GROW(refs->refs, refs->nr + 1, refs->alloc); } Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9c4c11 commit 43d20a8

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

refs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refna
360360
f = fopen(name, "r");
361361
if (!f)
362362
return -1;
363+
memset(&refs, 0, sizeof(refs));
363364
read_packed_refs(f, &refs);
364365
fclose(f);
365366
ref = search_ref_array(&refs.packed, refname);

0 commit comments

Comments
 (0)