]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
os-util: avoid matching on the wrong extension-release file
authorLuca Boccassi <bluca@debian.org>
Wed, 3 Jul 2024 20:27:28 +0000 (21:27 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 4 Jul 2024 10:49:28 +0000 (12:49 +0200)
The previous commit tries to extract a substring from the
extension-release suffix, but that is not right, it's only the
images that need to be versioned and extracted, use the extension-release
suffix as-is. Otherwise if it happens to contain a prefix that
matches the wrong image, it will be taken into account.

Follow-up for 37543971aff79f3a37646ffc2bb5845c9394797b

src/basic/os-util.c
test/units/TEST-29-PORTABLE.sh

index 0da4e9d079826517ab4e1b5df5384e78d08fca82..9b31a0d32576a6aba9ce202b5ce82aa4446bf52a 100644 (file)
@@ -259,13 +259,7 @@ int open_extension_release_at(
                 }
 
                 if (!relax_extension_release_check) {
-                        _cleanup_free_ char *base_image_name = NULL, *base_extension = NULL;
-
-                        r = path_extract_image_name(image_name, &base_image_name);
-                        if (r < 0) {
-                                log_debug_errno(r, "Failed to extract image name from %s/%s, ignoring: %m", dir_path, de->d_name);
-                                continue;
-                        }
+                        _cleanup_free_ char *base_extension = NULL;
 
                         r = path_extract_image_name(extension, &base_extension);
                         if (r < 0) {
@@ -273,7 +267,7 @@ int open_extension_release_at(
                                 continue;
                         }
 
-                        if (!streq(base_image_name, base_extension) &&
+                        if (!streq(image_name, base_extension) &&
                             extension_release_strict_xattr_value(fd, dir_path, image_name) != 0)
                                 continue;
                 }
index 27c24a0e6cc1a20902e39dff87997e9ce4179bb4..b4dcd5a1a294684210bb20ef6cb84c3d1c69a848 100755 (executable)
@@ -354,6 +354,17 @@ portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
 portablectl "${ARGS[@]}" attach --copy=symlink --now --runtime /tmp/rootdir minimal-app0
 portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
 
+# The wrong file should be ignored, given the right one has the xattr set
+mkdir -p /tmp/wrongext/usr/lib/extension-release.d /tmp/wrongext/usr/lib/systemd/system/
+echo "[Service]" > /tmp/wrongext/usr/lib/systemd/system/app0.service
+touch /tmp/wrongext/usr/lib/extension-release.d/extension-release.wrongext_somethingwrong.txt
+cp /tmp/rootdir/usr/lib/os-release /tmp/wrongext/usr/lib/extension-release.d/extension-release.app0
+setfattr -n user.extension-release.strict -v "false" /tmp/wrongext/usr/lib/extension-release.d/extension-release.app0
+portablectl "${ARGS[@]}" attach --runtime --extension /tmp/wrongext /tmp/rootdir app0
+status="$(portablectl is-attached --extension wrongext rootdir)"
+[[ "${status}" == "attached-runtime" ]]
+portablectl detach --runtime --extension /tmp/wrongext /tmp/rootdir app0
+
 umount /tmp/rootdir
 umount /tmp/app0
 umount /tmp/app1