Skip to content

Commit

Permalink
receive-pack: do not overallocate command structure
Browse files Browse the repository at this point in the history
An "update" command in the protocol exchange consists of 40-hex old
object name, SP, 40-hex new object name, SP, and a refname, but the
first instance is further followed by a NUL with feature requests.

The command structure, which has a flex-array member that stores the
refname at the end, was allocated based on the whole length of the
update command, without excluding the trailing feature requests.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Sep 15, 2014
1 parent aa544bf commit 3bfcb95
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions builtin/receive-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,11 @@ static struct command *read_head_info(struct sha1_array *shallow)
if (parse_feature_request(feature_list, "quiet"))
quiet = 1;
}
cmd = xcalloc(1, sizeof(struct command) + len - 80);
cmd = xcalloc(1, sizeof(struct command) + reflen + 1);
hashcpy(cmd->old_sha1, old_sha1);
hashcpy(cmd->new_sha1, new_sha1);
memcpy(cmd->ref_name, line + 82, len - 81);
memcpy(cmd->ref_name, refname, reflen);
cmd->ref_name[reflen] = '\0';
*p = cmd;
p = &cmd->next;
}
Expand Down

0 comments on commit 3bfcb95

Please sign in to comment.