rerere: replace strcpy with xsnprintf
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>
Jeff King committed
Feb 8, 2016 at 17:25 UTC
f58316db0ef1b25506c8cd6cc86b3071243a672a
1 file changed
+2
-2
rerere.c
+2
-2
@@ -50,7 +50,7 @@ static int has_rerere_resolution(const struct rerere_id *id)
50
static struct rerere_id *new_rerere_id_hex(char *hex)
51
{
52
struct rerere_id *id = xmalloc(sizeof(*id));
53
- strcpy(id->hex, hex);
53
+ xsnprintf(id->hex, sizeof(id->hex), "%s", hex);
54
return id;
55
}
56
@@ -900,7 +900,7 @@ int rerere_forget(struct pathspec *pathspec)
900
static struct rerere_id *dirname_to_id(const char *name)
901
{
902
static struct rerere_id id;
903
- strcpy(id.hex, name);
903
+ xsnprintf(id.hex, sizeof(id.hex), "%s", name);
904
return &id;
905
}
906