Package: dpkg
Version: 1.19.7
Tags: patch

When a package contains a symlink that reaches into a filesystem that can't
be accessed by root (due to missing key, errno=ENOKEY), installation works,
removal works, but upgrade or reinstallation of the package doesn't work
and fails because dpkg fails to stat the link target.

Patch attached, which fixes this issue, though I suspect other locations
should possibly use a similar logic.

As far as I understand (also mentioned in the header of the patch), this is
to avoid unpacking a link into a directory the link originally pointed to.
If that is the case, the patch should be fine, but I wonder if this
shouldn't be handled differently. But I would need to dig into the code
much more than I am comfortable with, given that this is C and I don't
usually use C. _If_ dpkg unpacks the package into some temporary directory
first and then moves the files into place, then there should be other
options to avoid the behavior mentioned.

Kind regards,
Sven
Description: When overwriting existing symlinks, treat ENOKEY like ENOENT.
 When trying to overwrite existing symlinks, dpkg tries to stat the target of
 the symlink to check if it points to a directory. Treate ENOKEY like ENOENT,
 as the point of the check is to ensure that the new file doesn't end up in the
 directory the symlink could be pointing to.
Author: Sven Mueller <sven.muelle...@gmail.com>
Last-Update: 2020-08-26
---
Index: dpkg-1.19.7/src/archives.c
===================================================================
--- dpkg-1.19.7.orig/src/archives.c
+++ dpkg-1.19.7/src/archives.c
@@ -626,7 +626,8 @@ linktosameexistingdir(const struct tar_e
 
   statr= stat(fname, &oldstab);
   if (statr) {
-    if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
+    if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR ||
+          errno == ENOKEY))
       ohshite(_("failed to stat (dereference) existing symlink '%.250s'"),
               fname);
     return false;

Reply via email to