Skip to content

Commit

Permalink
rerere: replace strcpy with xsnprintf
Browse files Browse the repository at this point in the history
This shouldn't overflow, as we are copying a sha1 hex into a
41-byte buffer. But it does not hurt to use a bound-checking
function, which protects us and makes auditing for overflows
easier.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Feb 8, 2016
1 parent 15ed07d commit f58316d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rerere.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int has_rerere_resolution(const struct rerere_id *id)
static struct rerere_id *new_rerere_id_hex(char *hex)
{
struct rerere_id *id = xmalloc(sizeof(*id));
strcpy(id->hex, hex);
xsnprintf(id->hex, sizeof(id->hex), "%s", hex);
return id;
}

Expand Down Expand Up @@ -900,7 +900,7 @@ int rerere_forget(struct pathspec *pathspec)
static struct rerere_id *dirname_to_id(const char *name)
{
static struct rerere_id id;
strcpy(id.hex, name);
xsnprintf(id.hex, sizeof(id.hex), "%s", name);
return &id;
}

Expand Down

0 comments on commit f58316d

Please sign in to comment.