Skip to content

Commit 330c8e2

Browse files
peffgitster
authored andcommitted
entry.c: convert strcpy to xsnprintf
This particular conversion is non-obvious, because nobody has passed our function the length of the destination buffer. However, the interface to checkout_entry specifies that the buffer must be at least TEMPORARY_FILENAME_LENGTH bytes long, so we can check that (meaning the existing code was not buggy, but merely worrisome to somebody reading it). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 19bdd3e commit 330c8e2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

entry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ static int open_output_fd(char *path, const struct cache_entry *ce, int to_tempf
9696
{
9797
int symlink = (ce->ce_mode & S_IFMT) != S_IFREG;
9898
if (to_tempfile) {
99-
strcpy(path, symlink
100-
? ".merge_link_XXXXXX" : ".merge_file_XXXXXX");
99+
xsnprintf(path, TEMPORARY_FILENAME_LENGTH, "%s",
100+
symlink ? ".merge_link_XXXXXX" : ".merge_file_XXXXXX");
101101
return mkstemp(path);
102102
} else {
103103
return create_file(path, !symlink ? ce->ce_mode : 0666);

0 commit comments

Comments
 (0)