Skip to content

Commit 3bfcb95

Browse files
committed
receive-pack: do not overallocate command structure
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 <[email protected]>
1 parent aa544bf commit 3bfcb95

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/receive-pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,11 @@ static struct command *read_head_info(struct sha1_array *shallow)
872872
if (parse_feature_request(feature_list, "quiet"))
873873
quiet = 1;
874874
}
875-
cmd = xcalloc(1, sizeof(struct command) + len - 80);
875+
cmd = xcalloc(1, sizeof(struct command) + reflen + 1);
876876
hashcpy(cmd->old_sha1, old_sha1);
877877
hashcpy(cmd->new_sha1, new_sha1);
878-
memcpy(cmd->ref_name, line + 82, len - 81);
878+
memcpy(cmd->ref_name, refname, reflen);
879+
cmd->ref_name[reflen] = '\0';
879880
*p = cmd;
880881
p = &cmd->next;
881882
}

0 commit comments

Comments
 (0)