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

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