Skip to content

Commit

Permalink
refs.c: ensure struct whose member may be passed to realloc is initia…
Browse files Browse the repository at this point in the history
…lized

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 <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Brandon Casey authored and Junio C Hamano committed Oct 10, 2011
1 parent e9c4c11 commit 43d20a8
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refna
f = fopen(name, "r");
if (!f)
return -1;
memset(&refs, 0, sizeof(refs));
read_packed_refs(f, &refs);
fclose(f);
ref = search_ref_array(&refs.packed, refname);
Expand Down

0 comments on commit 43d20a8

Please sign in to comment.