From 0c9c313ff857134107687ee559dd51b8cb42059e Mon Sep 17 00:00:00 2001
From: mirabilos <tg@mirbsd.org>
Date: Sat, 18 Nov 2017 16:57:13 +0100
Subject: =?UTF-8?q?use=20tar(1)=20to=20copy=20the=20extra=20directories?=
 =?UTF-8?q?=E2=80=99=20content?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

this should fix symlink traversal for preexisting copy targets

Signed-off-by: mirabilos <tg@mirbsd.org>
---
 mk/image.mk | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'mk')

diff --git a/mk/image.mk b/mk/image.mk
index cd9551e28..b69cd80d2 100644
--- a/mk/image.mk
+++ b/mk/image.mk
@@ -53,8 +53,13 @@ extra-install:
 	@-if [ -h ${TARGET_DIR}/etc/resolv.conf -a -f $(ADK_TOPDIR)/extra/etc/resolv.conf ];then \
 		rm ${TARGET_DIR}/etc/resolv.conf;\
 	fi
-	@if [ -d $(ADK_TOPDIR)/extra ];then $(CP) $(ADK_TOPDIR)/extra/* ${TARGET_DIR};fi
-	@if [ ! -z $(extra) ];then $(CP) $(extra)/* ${TARGET_DIR};fi
+	@if test -d '${ADK_TOPDIR}/extra'; then \
+		(cd '${ADK_TOPDIR}/extra' && tar -cf - .) | \
+		    (cd ${TARGET_DIR}; tar -xf -); \
+	fi
+ifneq (,$(strip ${extra}))
+	@(cd '${extra}' && tar -cf - .) | (cd ${TARGET_DIR}; tar -xf -)
+endif
 
 image-prepare-post:
 	$(BASH) $(ADK_TOPDIR)/scripts/update-rcconf
-- 
cgit v1.2.3