Ben Hutchings 984bdc7d72 hook-functions: copy_file: Canonicalise target filename
When updating copy_file I have assumed that expected the target
argument is an absolute file (or directory) name.  This was not
previously required, and is even our own example hook does not include
a leading "/".

This is a longstanding bug, but apparently didn't have much of an
effect until commit b641a97705c1 ("hook_functions: Fix copy_file with
source including a directory symlink").

The reiserfsprogs hook runs:

    copy_exec /sbin/reiserfsck sbin/reiserfsck

which now results in:

    src=/sbin/reiserfsck
    target=sbin/reiserfsck            # did not match usr-merge patterns
    link_target=/usr/sbin/reiserfsck  # host is usr-merged

We make a symlink from ${DESTDIR}//usr/sbin/reiserfsck to
${DESTDIR}/sbin/reiserfsck, i.e. a self-link, and try to copy
/usr/sbin/reiserfsck to ${DESTDIR}/sbin/reiserfsck, which fails.

Prepend a "/" to the target and canonicalise it with "realpath -ms"
before doing any filename comparisons.

Fixes: e5476bff04c0 ("copy_file: Skip duplicating symlink if it points to ...")
Fixes: 4807ede18d88 ("hook-functions: Avoid symlinks that conflict with ...")
Closes: #1079276
Signed-off-by: Ben Hutchings <benh@debian.org>
2024-08-22 16:40:08 +02:00
2024-08-22 01:59:42 +02:00
2023-02-27 22:29:35 +10:00
Description
initramfs-tools
2 MiB
Languages
Shell 68.3%
Roff 22.3%
C 9.3%