git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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)
Previous: Junio C HamanoNext: Willy Tarreau
Message 4 of 14 in “What's in git.git, and announcing GIT 1.4.2-rc4”
  1. Junio C HamanoAug 10, 2006
  2. Willy TarreauAug 10, 2006
  3. Junio C HamanoAug 10, 2006
  4. Junio C HamanoAug 10, 2006
  5. Willy TarreauAug 10, 2006
  6. Johannes SchindelinAug 10, 2006
  7. Junio C HamanoAug 10, 2006
  8. Johannes SchindelinAug 10, 2006
  9. Junio C HamanoAug 10, 2006
  10. Junio C HamanoAug 10, 2006
  11. Johannes SchindelinAug 10, 2006
  12. Alex RiesenAug 10, 2006
  13. Johannes SchindelinAug 10, 2006
  14. Alex RiesenAug 10, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.