Skip to content

Commit a5c4f22

Browse files
committed
os-util: avoid matching on the wrong extension-release file
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 3754397 (cherry picked from commit 92d1fe3) (cherry picked from commit 160b539) (cherry picked from commit 129a548)
1 parent 25bd5f4 commit a5c4f22

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/basic/os-util.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,21 +272,15 @@ int open_extension_release_at(
272272
}
273273

274274
if (!relax_extension_release_check) {
275-
_cleanup_free_ char *base_image_name = NULL, *base_extension = NULL;
276-
277-
r = path_extract_image_name(image_name, &base_image_name);
278-
if (r < 0) {
279-
log_debug_errno(r, "Failed to extract image name from %s/%s, ignoring: %m", dir_path, de->d_name);
280-
continue;
281-
}
275+
_cleanup_free_ char *base_extension = NULL;
282276

283277
r = path_extract_image_name(extension, &base_extension);
284278
if (r < 0) {
285279
log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", extension);
286280
continue;
287281
}
288282

289-
if (!streq(base_image_name, base_extension) &&
283+
if (!streq(image_name, base_extension) &&
290284
extension_release_strict_xattr_value(fd, dir_path, image_name) != 0)
291285
continue;
292286
}

test/units/testsuite-29.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,17 @@ portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
264264
portablectl "${ARGS[@]}" attach --copy=symlink --now --runtime /tmp/rootdir minimal-app0
265265
portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
266266

267+
# The wrong file should be ignored, given the right one has the xattr set
268+
mkdir -p /tmp/wrongext/usr/lib/extension-release.d /tmp/wrongext/usr/lib/systemd/system/
269+
echo "[Service]" > /tmp/wrongext/usr/lib/systemd/system/app0.service
270+
touch /tmp/wrongext/usr/lib/extension-release.d/extension-release.wrongext_somethingwrong.txt
271+
cp /tmp/rootdir/usr/lib/os-release /tmp/wrongext/usr/lib/extension-release.d/extension-release.app0
272+
setfattr -n user.extension-release.strict -v "false" /tmp/wrongext/usr/lib/extension-release.d/extension-release.app0
273+
portablectl "${ARGS[@]}" attach --runtime --extension /tmp/wrongext /tmp/rootdir app0
274+
status="$(portablectl is-attached --extension wrongext rootdir)"
275+
[[ "${status}" == "attached-runtime" ]]
276+
portablectl detach --runtime --extension /tmp/wrongext /tmp/rootdir app0
277+
267278
umount /tmp/rootdir
268279
umount /tmp/app0
269280
umount /tmp/app1

0 commit comments

Comments
 (0)