Commit 32596e16badddcbd6c032b6367d125df0e421f4b

Stefan Sperling 2020-07-23T14:21:28

fix got_tree_entry_get_symlink_target() in case of multiple loop iterations

diff --git a/lib/object.c b/lib/object.c
index 525bbd9..cfc0d4b 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -869,7 +869,7 @@ got_tree_entry_get_symlink_target(char **link_target, struct got_tree_entry *te,
 {
 	const struct got_error *err = NULL;
 	struct got_blob_object *blob = NULL;
-	size_t len, totlen, hdrlen;
+	size_t len, totlen, hdrlen, offset;
 
 	*link_target = NULL;
 
@@ -882,6 +882,7 @@ got_tree_entry_get_symlink_target(char **link_target, struct got_tree_entry *te,
 		return err;
 	hdrlen = got_object_blob_get_hdrlen(blob);
 	totlen = 0;
+	offset = 0;
 	do {
 		char *p;
 
@@ -900,9 +901,10 @@ got_tree_entry_get_symlink_target(char **link_target, struct got_tree_entry *te,
 		}
 		*link_target = p;
 		/* Skip blob object header first time around. */
-		memcpy(*link_target,
+		memcpy(*link_target + offset,
 		    got_object_blob_get_read_buf(blob) + hdrlen, len - hdrlen);
 		hdrlen = 0;
+		offset = totlen;
 	} while (len > 0);
 	(*link_target)[totlen] = '\0';
 done: