use sha1_to_hex_r() instead of strcpy
Before sha1_to_hex_r() existed, a simple way to get hex sha1 into a buffer was with: strcpy(buf, sha1_to_hex(sha1)); This isn't wrong (assuming the buf is 41 characters), but it makes auditing the code base for bad strcpy() calls harder, as these become false positives. Let's convert them to sha1_to_hex_r(), and likewise for some calls to find_unique_abbrev(). While we're here, we'll double-check that all of the buffers are correctly sized, and use the more obvious GIT_SHA1_HEXSZ constant. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
f063d38b80
commit
d59f765ac9
@ -217,7 +217,7 @@ static void print_var_int(const char *var, int val)
|
||||
static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
|
||||
{
|
||||
int cnt, flags = info->flags;
|
||||
char hex[41] = "";
|
||||
char hex[GIT_SHA1_HEXSZ + 1] = "";
|
||||
struct commit_list *tried;
|
||||
struct rev_info *revs = info->revs;
|
||||
|
||||
@ -242,7 +242,7 @@ static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
|
||||
cnt = reaches;
|
||||
|
||||
if (revs->commits)
|
||||
strcpy(hex, sha1_to_hex(revs->commits->item->object.sha1));
|
||||
sha1_to_hex_r(hex, revs->commits->item->object.sha1);
|
||||
|
||||
if (flags & BISECT_SHOW_ALL) {
|
||||
traverse_commit_list(revs, show_commit, show_object, info);
|
||||
|
Reference in New Issue
Block a user