Skip to content

hook-functions: copy_file: Canonicalise target filename

Ben Hutchings requested to merge benh/initramfs-tools:bug1079276 into master

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 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 b641a977 ("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 then 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: e5476bff ("copy_file: Skip duplicating symlink if it points to ...")
Fixes: 4807ede1 ("hook-functions: Avoid symlinks that conflict with ...")
Closes: #1079276

Edited by Ben Hutchings

Merge request reports

Loading