Re: What's in git.git, and announcing GIT 1.4.2-rc4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Junio C Hamano <junkio@xxxxxxx> writes:

> Willy Tarreau <w@xxxxxx> 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)

-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]