diff options
author | Mike Frysinger <vapier@chromium.org> | 2021-04-16 10:49:56 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2021-04-16 10:49:56 -0400 |
commit | 080a59e801e121ebadc3e1e170e57ca27de15876 (patch) | |
tree | b82cecbb00ef1d67ce6fc60061b1efda0a50b7a9 | |
parent | lddtree: handle ${ORIGIN} like $ORIGIN (diff) | |
download | pax-utils-080a59e801e121ebadc3e1e170e57ca27de15876.tar.gz pax-utils-080a59e801e121ebadc3e1e170e57ca27de15876.tar.bz2 pax-utils-080a59e801e121ebadc3e1e170e57ca27de15876.zip |
lddtree: handle relative ldpaths
Tweak the ldpath logic to handle all relative paths relative to the
cwd instead of the root. Such ELFs are uncommon and weird, but not
invalid, so might as well.
Bug: https://bugs.gentoo.org/653586
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rwxr-xr-x | lddtree.py | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -184,7 +184,7 @@ exec \\ @functools.lru_cache(maxsize=None) -def ParseLdPaths(str_ldpaths, root='', path=None): +def ParseLdPaths(str_ldpaths, root='', cwd=None, path=None): """Parse the colon-delimited list of paths and apply ldso rules to each Note the special handling as dictated by the ldso: @@ -195,23 +195,34 @@ def ParseLdPaths(str_ldpaths, root='', path=None): Args: str_ldpaths: A colon-delimited string of paths root: The path to prepend to all paths found + cwd: The path to resolve relative paths against (defaults to getcwd()). path: The object actively being parsed (used for $ORIGIN) Returns: list of processed paths """ + if cwd is None: + cwd = os.getcwd() + ldpaths = [] for ldpath in str_ldpaths.split(':'): - if not ldpath: - # The ldso treats "" paths as $PWD. - ldpath = os.getcwd() - elif '$ORIGIN' in ldpath: + # Expand placeholders first. + if '$ORIGIN' in ldpath: ldpath = ldpath.replace('$ORIGIN', os.path.dirname(path)) elif '${ORIGIN}' in ldpath: ldpath = ldpath.replace('${ORIGIN}', os.path.dirname(path)) + + # Expand relative paths if needed. These don't make sense in general, + # but that doesn't stop people from using them. As such, root prefix + # doesn't make sense with it either. + if not ldpath.startswith('/'): + # NB: The ldso treats "" paths as cwd too. + ldpath = os.path.join(cwd, ldpath) else: ldpath = root + ldpath + ldpaths.append(normpath(ldpath)) + return dedupe(ldpaths) |