mirror of
https://git.yoctoproject.org/poky
synced 2026-04-17 18:32:12 +02:00
populate_sdk_base: Add sysroot symlink check
Add optional check to do_populate_sdk() that verifies SDK sysroots don't contain dangling or escaping symlinks before attempting to tar an archive. Such links may fail a `tar -h` operation (-h => follow symlinks) or archive the build system's files. Set CHECK_SDK_SYSROOTS = "1" to enable this check. Use case: The -h option may be set via SDKTAROPTS in some configurations to create symlink-less SDK archives for Windows file systems. (From OE-Core rev: 2658200fa2b3df08880ee937a3de5cb2866f8a50) Signed-off-by: Haris Okanovic <haris.okanovic@ni.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
7fed65564d
commit
5ba638210c
@@ -80,7 +80,7 @@ python write_host_sdk_manifest () {
|
||||
|
||||
POPULATE_SDK_POST_TARGET_COMMAND_append = " write_target_sdk_manifest ; "
|
||||
POPULATE_SDK_POST_HOST_COMMAND_append = " write_host_sdk_manifest; "
|
||||
SDK_POSTPROCESS_COMMAND = " create_sdk_files; tar_sdk; ${SDK_PACKAGING_FUNC}; "
|
||||
SDK_POSTPROCESS_COMMAND = " create_sdk_files; check_sdk_sysroots; tar_sdk; ${SDK_PACKAGING_FUNC}; "
|
||||
|
||||
# Some archs override this, we need the nativesdk version
|
||||
# turns out this is hard to get from the datastore due to TRANSLATED_TARGET_ARCH
|
||||
@@ -120,6 +120,57 @@ fakeroot create_sdk_files() {
|
||||
sed -i -e "s:##DEFAULT_INSTALL_DIR##:$escaped_sdkpath:" ${SDK_OUTPUT}/${SDKPATH}/relocate_sdk.py
|
||||
}
|
||||
|
||||
python check_sdk_sysroots() {
|
||||
# Fails build if there are broken or dangling symlinks in SDK sysroots
|
||||
|
||||
if d.getVar('CHECK_SDK_SYSROOTS', True) != '1':
|
||||
# disabled, bail out
|
||||
return
|
||||
|
||||
def norm_path(path):
|
||||
return os.path.abspath(path)
|
||||
|
||||
# Get scan root
|
||||
SCAN_ROOT = norm_path("${SDK_OUTPUT}/${SDKPATH}/sysroots/")
|
||||
|
||||
bb.note('Checking SDK sysroots at ' + SCAN_ROOT)
|
||||
|
||||
def check_symlink(linkPath):
|
||||
if not os.path.islink(linkPath):
|
||||
return
|
||||
|
||||
linkDirPath = os.path.dirname(linkPath)
|
||||
|
||||
targetPath = os.readlink(linkPath)
|
||||
if not os.path.isabs(targetPath):
|
||||
targetPath = os.path.join(linkDirPath, targetPath)
|
||||
targetPath = norm_path(targetPath)
|
||||
|
||||
if SCAN_ROOT != os.path.commonprefix( [SCAN_ROOT, targetPath] ):
|
||||
bb.error("Escaping symlink {0!s} --> {1!s}".format(linkPath, targetPath))
|
||||
return
|
||||
|
||||
if not os.path.exists(targetPath):
|
||||
bb.error("Broken symlink {0!s} --> {1!s}".format(linkPath, targetPath))
|
||||
return
|
||||
|
||||
if os.path.isdir(targetPath):
|
||||
dir_walk(targetPath)
|
||||
|
||||
def walk_error_handler(e):
|
||||
bb.error(str(e))
|
||||
|
||||
def dir_walk(rootDir):
|
||||
for dirPath,subDirEntries,fileEntries in os.walk(rootDir, followlinks=False, onerror=walk_error_handler):
|
||||
entries = subDirEntries + fileEntries
|
||||
for e in entries:
|
||||
ePath = os.path.join(dirPath, e)
|
||||
check_symlink(ePath)
|
||||
|
||||
# start
|
||||
dir_walk(SCAN_ROOT)
|
||||
}
|
||||
|
||||
SDKTAROPTS = "--owner=root --group=root"
|
||||
|
||||
fakeroot tar_sdk() {
|
||||
|
||||
Reference in New Issue
Block a user