dracut/backport-fix-install-handle-LIB-in-ldd-output-parsing.patch
zhangruifang2020 731a2bcd17 backport patchs from upstream
(cherry picked from commit 2e01aee7d2264d9f95b58cf86ca965c343e44027)
2023-12-20 11:12:15 +08:00

58 lines
2.0 KiB
Diff

From d1a36d3d80b0ed71ee814659e18a020c53cee05e Mon Sep 17 00:00:00 2001
From: Jaroslav Jindrak <dzejrou@gmail.com>
Date: Fri, 7 May 2021 15:11:55 +0200
Subject: [PATCH] fix(install): handle $LIB in ldd output parsing
The ldd output can contain the variable $LIB, which is a documented feature of
ldd. In a previous commit [0], dracut-install received support for this
variable, but that was later reverted [1] due to issues [2][3] on Gentoo ARM64.
The part before '=>' does not necessarily refer to an existing file (e.g. due
to the usage of $LIB) and thus [1] could be seen as a regression to anyone
that uses this ldd feature. This PR combines both cases together and whenever
it find a '$' character (i.e. a variable) on the left side of the '=>' symbol,
it uses the right hand path (and thus uses evaluation done by ldd), otherwise
falls back to the behavior set by [1].
Reproducer that was presented to me:
$ grep "ibz.so" /etc/ld.so.preload || cat << EOF >> /etc/ld.so.preload
/\$LIB/libz.so.1.2.11
EOF
$ mkdir -p /var/tmp/dracut.xitk6p/initramfs
$ strace /usr/lib/dracut/dracut-install -D /var/tmp/dracut.xitk6p/initramfs -l /bin/bash 2>&1|grep ibz
$ rm -rf /var/tmp/dracut.xitk6p/
[0] 45404a2
[1] 6d886bb
[2] #471
[3] https://bugs.gentoo.org/667752
---
src/install/dracut-install.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/install/dracut-install.c b/src/install/dracut-install.c
index b4eec363..9f044ae0 100644
--- a/install/dracut-install.c
+++ b/install/dracut-install.c
@@ -589,7 +589,15 @@ static int resolve_deps(const char *src)
if (strstr(buf, destrootdir))
break;
- p = strchr(buf, '/');
+ p = buf;
+ if (strchr(p, '$')) {
+ /* take ldd variable expansion into account */
+ p = strstr(p, "=>");
+ if (!p)
+ p = buf;
+ }
+ p = strchr(p, '/');
+
if (p) {
char *q;
--
2.33.0