Blame SOURCES/0001-Validate-path-read-from-repomd.xml-RhBug-1866498.patch

33b946
From 699d3ee7b8968b5586ceb53e07d678e702735609 Mon Sep 17 00:00:00 2001
33b946
From: Jaroslav Rohel <jrohel@redhat.com>
33b946
Date: Wed, 12 Aug 2020 08:35:28 +0200
33b946
Subject: [PATCH] Validate path read from repomd.xml
33b946
33b946
---
33b946
 librepo/yum.c | 17 +++++++++++++++++
33b946
 1 file changed, 17 insertions(+)
33b946
33b946
diff --git a/librepo/yum.c b/librepo/yum.c
33b946
index 3059188..529257b 100644
33b946
--- a/librepo/yum.c
33b946
+++ b/librepo/yum.c
33b946
@@ -23,6 +23,7 @@
33b946
 #define  BITS_IN_BYTE 8
33b946
 
33b946
 #include <stdio.h>
33b946
+#include <libgen.h>
33b946
 #include <assert.h>
33b946
 #include <stdlib.h>
33b946
 #include <errno.h>
33b946
@@ -770,6 +771,22 @@ prepare_repo_download_targets(LrHandle *handle,
33b946
             continue;
33b946
 
33b946
         char *location_href = record->location_href;
33b946
+
33b946
+        char *dest_dir = realpath(handle->destdir, NULL);
33b946
+        path = lr_pathconcat(handle->destdir, record->location_href, NULL);
33b946
+        char *requested_dir = realpath(dirname(path), NULL);
33b946
+        lr_free(path);
33b946
+        if (!g_str_has_prefix(requested_dir, dest_dir)) {
33b946
+            g_debug("%s: Invalid path: %s", __func__, location_href);
33b946
+            g_set_error(err, LR_YUM_ERROR, LRE_IO, "Invalid path: %s", location_href);
33b946
+            g_slist_free_full(*targets, (GDestroyNotify) lr_downloadtarget_free);
33b946
+            free(requested_dir);
33b946
+            free(dest_dir);
33b946
+            return FALSE;
33b946
+        }
33b946
+        free(requested_dir);
33b946
+        free(dest_dir);
33b946
+
33b946
         gboolean is_zchunk = FALSE;
33b946
         #ifdef WITH_ZCHUNK
33b946
         if (handle->cachedir && record->header_checksum)
33b946
-- 
33b946
2.28.0
33b946