checkout: do not make a temporary copy of symlink target.
If the index records an insanely long symbolic link, copying into the temporary would overflow the buffer (noticed by Mark Wooding). Because read_sha1_file() terminates the returned buffer with NUL since late May 2005, there is no reason to copy it anymore. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 27, 2006 at 14:44 UTC
1ecc18e4fc0c91e9cab1aafbedb0eebdebaa8dd3
1 file changed
+3
-6
entry.c
+3
-6
@@ -70,7 +70,6 @@ static int write_entry(struct cache_entry *ce, const char *path, struct checkout
70
unsigned long size;
71
long wrote;
72
char type[20];
73
- char target[1024];
73
74
new = read_sha1_file(ce->sha1, type, &size);
75
if (!new || strcmp(type, "blob")) {
@@ -94,12 +93,10 @@ static int write_entry(struct cache_entry *ce, const char *path, struct checkout
93
return error("git-checkout-index: unable to write file %s", path);
94
break;
95
case S_IFLNK:
97
- memcpy(target, new, size);
98
- target[size] = '\0';
99
- if (symlink(target, path)) {
96
+ if (symlink(new, path)) {
97
free(new);
101
- return error("git-checkout-index: unable to create symlink %s (%s)",
102
- path, strerror(errno));
98
+ return error("git-checkout-index: unable to create "
99
+ "symlink %s (%s)", path, strerror(errno));
100
}
101
free(new);
102
break;