From f6e8c23f3e856c4b666bbe443a30ca6dabb3dadf Mon Sep 17 00:00:00 2001
From: Thijs Kinkhorst <thijs@kinkhorst.com>
Date: Wed, 12 Feb 2020 15:45:01 +0000
Subject: [PATCH] Fix metadata converter which was broken in multiple ways.

Non-file-upload crashed on Symfony request building.
File upload crashed because of not using the actual path.
---
 lib/SimpleSAML/Module.php                   | 4 +++-
 modules/admin/lib/Controller/Federation.php | 3 +--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/SimpleSAML/Module.php b/lib/SimpleSAML/Module.php
index 696f8cfd5..e536c105f 100644
--- a/lib/SimpleSAML/Module.php
+++ b/lib/SimpleSAML/Module.php
@@ -173,12 +173,14 @@ class Module
         $translated_uri = $config->getBasePath() . 'module.php/' . $module . '/' . $url;
         $request->server->set('REQUEST_URI', $translated_uri);
         $request->server->set('SCRIPT_NAME', $config->getBasePath() . 'module.php');
+        // strip any NULL files (form file fields with nothing selected) because initialize() will throw an error on them
+        $request_files = array_filter($request->files->all(), function($val){return !is_null($val);});
         $request->initialize(
             $request->query->all(),
             $request->request->all(),
             $request->attributes->all(),
             $request->cookies->all(),
-            $request->files->all(),
+            $request_files ?? [],
             $request->server->all(),
             $request->getContent()
         );
diff --git a/modules/admin/lib/Controller/Federation.php b/modules/admin/lib/Controller/Federation.php
index 351e91ec7..c7e2165d9 100644
--- a/modules/admin/lib/Controller/Federation.php
+++ b/modules/admin/lib/Controller/Federation.php
@@ -395,9 +395,8 @@ class Federation
     public function metadataConverter(Request $request)
     {
         Utils\Auth::requireAdmin();
-
         if ($xmlfile = $request->files->get('xmlfile')) {
-            $xmldata = trim(file_get_contents($xmlfile));
+            $xmldata = trim(file_get_contents($xmlfile->getPathname()));
         } elseif ($xmldata = $request->request->get('xmldata')) {
             $xmldata = trim($xmldata);
         }
-- 
GitLab