Re: What's in git.git, and announcing GIT 1.4.2-rc4
- From
Junio C Hamano <junkio@cox.net>
- Date
- Aug 10, 2006, 05:43 UTC
- Message-ID
- <7vfyg5xi02.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <7vu04lxjsv.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> writes:
Show 8 quoted lines
> Willy Tarreau <w@1wt.eu> writes: > >> I encountered a problem in 1.4.1 and 1.4-git about 2 weeks ago >> (I've not tried 1.4.2-rc4 yet). When applying a git patch which >> contains a symlink, the symlink created on the filesystem sometimes >> has a wrong name with some chars appended to its end. > > Thanks. I can reproduce this, and am looking into it.
Found it. The patch application mechanism uses a counted string (char *buf with ulong size) to hold the result, and the code stupidly threw the buf to symlink(2), without making it NUL terminated.
diff --git a/builtin-apply.c b/builtin-apply.c index f8c6763..c159873 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1698,6 +1698,14 @@ static int apply_data(struct patch *patc desc.buffer = buf; if (apply_fragments(&desc, patch) < 0) return -1; + + /* NUL terminate the result */ + if (desc.alloc <= desc.size) { + desc.buffer = xrealloc(desc.buffer, desc.size + 1); + desc.alloc++; + } + desc.buffer[desc.size] = 0; + patch->result = desc.buffer; patch->resultsize = desc.size; @@ -2040,6 +2048,9 @@ static int try_create_file(const char *p int fd; if (S_ISLNK(mode)) + /* Although buf:size is counted string, it also is NUL + * terminated. + */ return symlink(buf, path); fd = open(path, O_CREAT | O_EXCL | O_WRONLY, (mode & 0100) ? 0777 : 0666); if (fd < 0)