Skip to content

Commit f58316d

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 15ed07d commit f58316d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

rerere.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static int has_rerere_resolution(const struct rerere_id *id)
5050
static struct rerere_id *new_rerere_id_hex(char *hex)
5151
{
5252
struct rerere_id *id = xmalloc(sizeof(*id));
53-
strcpy(id->hex, hex);
53+
xsnprintf(id->hex, sizeof(id->hex), "%s", hex);
5454
return id;
5555
}
5656

@@ -900,7 +900,7 @@ int rerere_forget(struct pathspec *pathspec)
900900
static struct rerere_id *dirname_to_id(const char *name)
901901
{
902902
static struct rerere_id id;
903-
strcpy(id.hex, name);
903+
xsnprintf(id.hex, sizeof(id.hex), "%s", name);
904904
return &id;
905905
}
906906

0 commit comments

Comments
 (0)