summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Vogt <fvogt@suse.de>2022-03-09 13:37:49 +0100
committerRichard Hughes <richard@hughsie.com>2022-03-09 20:06:59 +0000
commit87e1aa8774dad3e6b504c641938e84490116088f (patch)
tree95f9f7b6c5aad0cbf469cd812d841079032fbd7b
parent349799ba1d026a18012520b9f2e1901a88ac467b (diff)
downloadappstream-glib-87e1aa8774dad3e6b504c641938e84490116088f.tar.gz
Fix extracting relative symlinks
ebdefa2745 tried to fix handling of relative symlinks in archives, but that only addressed targets starting with ".."/. Fix it properly by using asb_utils_sanitise_path only for absolute paths, keep relative paths as-is. Simplify code for handling absolute symlinks by just prepending the root instead of converting it to a relative link. Hardlink targets are returned as paths relative to the archive root, so the sanitization code is correct there.
-rw-r--r--data/tests/app-1-1.fc25.x86_64.rpmbin14306 -> 16758 bytes
-rw-r--r--data/tests/app.spec7
-rw-r--r--libappstream-builder/asb-utils.c49
3 files changed, 10 insertions, 46 deletions
diff --git a/data/tests/app-1-1.fc25.x86_64.rpm b/data/tests/app-1-1.fc25.x86_64.rpm
index ac601ce..b2d770c 100644
--- a/data/tests/app-1-1.fc25.x86_64.rpm
+++ b/data/tests/app-1-1.fc25.x86_64.rpm
Binary files differ
diff --git a/data/tests/app.spec b/data/tests/app.spec
index 26dbfb9..b40519a 100644
--- a/data/tests/app.spec
+++ b/data/tests/app.spec
@@ -53,11 +53,13 @@ cd $RPM_BUILD_ROOT
ln -s %{_datadir}/app/app-48x48.png usr/share/icons/hicolor/48x48/apps/app.png
cd -
-# test decompressing a relative symlink destination
+# test decompressing relative symlink destinations
install -Dp %{SOURCE18} $RPM_BUILD_ROOT%{_datadir}/app/app-128x128.png
mkdir -p $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/128x128/apps
cd $RPM_BUILD_ROOT
-ln -s ../../../../app/app-128x128.png usr/share/icons/hicolor/128x128/apps/app.png
+# Test links in the same directory as well as outside
+ln -s ../../../../app/app-128x128.png usr/share/icons/hicolor/128x128/apps/app-linked.png
+ln -s app-linked.png usr/share/icons/hicolor/128x128/apps/app.png
cd -
install -Dp %{SOURCE3} $RPM_BUILD_ROOT/%{_datadir}/appdata/app.appdata.xml
@@ -93,6 +95,7 @@ install -Dp %{SOURCE16} $RPM_BUILD_ROOT/%{_datadir}/applications/console2.deskto
%{_datadir}/app/app-48x48.png
%{_datadir}/app/app-128x128.png
%{_datadir}/icons/hicolor/48x48/apps/app.png
+%{_datadir}/icons/hicolor/128x128/apps/app-linked.png
%{_datadir}/icons/hicolor/128x128/apps/app.png
%files extra
diff --git a/libappstream-builder/asb-utils.c b/libappstream-builder/asb-utils.c
index d1ee2ad..deb2858 100644
--- a/libappstream-builder/asb-utils.c
+++ b/libappstream-builder/asb-utils.c
@@ -155,32 +155,6 @@ asb_utils_ensure_exists_and_empty (const gchar *directory, GError **error)
return TRUE;
}
-static guint
-asb_utils_count_directories_deep (const gchar *path)
-{
- guint cnt = 0;
- guint i;
-
- for (i = 0; path[i] != '\0'; i++) {
- if (path[i] != '/')
- continue;
- cnt++;
- }
- return cnt;
-}
-
-static gchar *
-asb_utils_get_back_to_root (guint levels)
-{
- GString *str;
- guint i;
-
- str = g_string_new ("");
- for (i = 0; i < levels; i++)
- g_string_append (str, "../");
- return g_string_free (str, FALSE);
-}
-
static gchar *
asb_utils_sanitise_path (const gchar *path)
{
@@ -243,25 +217,12 @@ asb_utils_explode_file (struct archive_entry *entry, const gchar *dir)
archive_entry_update_hardlink_utf8 (entry, buf_link);
}
- /* update symlinks */
+ /* update absolute symlinks */
tmp = archive_entry_symlink (entry);
- if (tmp != NULL) {
- g_autofree gchar *path_link = NULL;
-
- path_link = asb_utils_sanitise_path (tmp);
- if (g_path_is_absolute (path_link)) {
- guint symlink_depth;
- g_autofree gchar *back_up = NULL;
- g_autofree gchar *buf_link = NULL;
-
- symlink_depth = asb_utils_count_directories_deep (path) - 1;
- back_up = asb_utils_get_back_to_root (symlink_depth);
- buf_link = g_build_filename (back_up, tmp, NULL);
-
- archive_entry_update_symlink_utf8 (entry, buf_link);
- } else {
- archive_entry_update_symlink_utf8 (entry, path_link);
- }
+ if (tmp != NULL && g_path_is_absolute (tmp)) {
+ g_autofree gchar *buf_link = NULL;
+ buf_link = g_build_filename (dir, tmp, NULL);
+ archive_entry_update_symlink_utf8 (entry, buf_link);
}
return TRUE;
}