aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@chromium.org>2021-04-16 10:49:56 -0400
committerMike Frysinger <vapier@gentoo.org>2021-04-16 10:49:56 -0400
commit080a59e801e121ebadc3e1e170e57ca27de15876 (patch)
treeb82cecbb00ef1d67ce6fc60061b1efda0a50b7a9
parentlddtree: handle ${ORIGIN} like $ORIGIN (diff)
downloadpax-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-xlddtree.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/lddtree.py b/lddtree.py
index cd068f6..d91e729 100755
--- a/lddtree.py
+++ b/lddtree.py
@@ -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)