1 |
commit: 080a59e801e121ebadc3e1e170e57ca27de15876 |
2 |
Author: Mike Frysinger <vapier <AT> chromium <DOT> org> |
3 |
AuthorDate: Fri Apr 16 14:49:56 2021 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Apr 16 14:49:56 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=080a59e8 |
7 |
|
8 |
lddtree: handle relative ldpaths |
9 |
|
10 |
Tweak the ldpath logic to handle all relative paths relative to the |
11 |
cwd instead of the root. Such ELFs are uncommon and weird, but not |
12 |
invalid, so might as well. |
13 |
|
14 |
Bug: https://bugs.gentoo.org/653586 |
15 |
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> |
16 |
|
17 |
lddtree.py | 21 ++++++++++++++++----- |
18 |
1 file changed, 16 insertions(+), 5 deletions(-) |
19 |
|
20 |
diff --git a/lddtree.py b/lddtree.py |
21 |
index cd068f6..d91e729 100755 |
22 |
--- a/lddtree.py |
23 |
+++ b/lddtree.py |
24 |
@@ -184,7 +184,7 @@ exec \\ |
25 |
|
26 |
|
27 |
@functools.lru_cache(maxsize=None) |
28 |
-def ParseLdPaths(str_ldpaths, root='', path=None): |
29 |
+def ParseLdPaths(str_ldpaths, root='', cwd=None, path=None): |
30 |
"""Parse the colon-delimited list of paths and apply ldso rules to each |
31 |
|
32 |
Note the special handling as dictated by the ldso: |
33 |
@@ -195,23 +195,34 @@ def ParseLdPaths(str_ldpaths, root='', path=None): |
34 |
Args: |
35 |
str_ldpaths: A colon-delimited string of paths |
36 |
root: The path to prepend to all paths found |
37 |
+ cwd: The path to resolve relative paths against (defaults to getcwd()). |
38 |
path: The object actively being parsed (used for $ORIGIN) |
39 |
|
40 |
Returns: |
41 |
list of processed paths |
42 |
""" |
43 |
+ if cwd is None: |
44 |
+ cwd = os.getcwd() |
45 |
+ |
46 |
ldpaths = [] |
47 |
for ldpath in str_ldpaths.split(':'): |
48 |
- if not ldpath: |
49 |
- # The ldso treats "" paths as $PWD. |
50 |
- ldpath = os.getcwd() |
51 |
- elif '$ORIGIN' in ldpath: |
52 |
+ # Expand placeholders first. |
53 |
+ if '$ORIGIN' in ldpath: |
54 |
ldpath = ldpath.replace('$ORIGIN', os.path.dirname(path)) |
55 |
elif '${ORIGIN}' in ldpath: |
56 |
ldpath = ldpath.replace('${ORIGIN}', os.path.dirname(path)) |
57 |
+ |
58 |
+ # Expand relative paths if needed. These don't make sense in general, |
59 |
+ # but that doesn't stop people from using them. As such, root prefix |
60 |
+ # doesn't make sense with it either. |
61 |
+ if not ldpath.startswith('/'): |
62 |
+ # NB: The ldso treats "" paths as cwd too. |
63 |
+ ldpath = os.path.join(cwd, ldpath) |
64 |
else: |
65 |
ldpath = root + ldpath |
66 |
+ |
67 |
ldpaths.append(normpath(ldpath)) |
68 |
+ |
69 |
return dedupe(ldpaths) |