summaryrefslogtreecommitdiff
path: root/libappstream-builder/asb-utils.c
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 /libappstream-builder/asb-utils.c
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.
Diffstat (limited to 'libappstream-builder/asb-utils.c')
-rw-r--r--libappstream-builder/asb-utils.c49
1 files changed, 5 insertions, 44 deletions
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;
}