From 6685432a97d81595fc6eb0c9d292374b11becb47 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Thu, 28 May 2015 21:35:34 +0200 Subject: [PATCH] [linker] Fortify the BlacklistStep. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit [merged from monodroid by rodo] commit 3001f693c52be0da673446179daf498265024867 Author: Alex Rønne Petersen Date: Tue Jul 30 20:06:21 2013 +0200 1. Catch XmlExceptions in case of broken XML files. 2. Only process files that actually end in ".xml". --- .../linker/Mono.Linker.Steps/BlacklistStep.cs | 14 +++++++++++++- mcs/tools/linker/Mono.Linker/LinkContext.cs | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mcs/tools/linker/Mono.Linker.Steps/BlacklistStep.cs b/mcs/tools/linker/Mono.Linker.Steps/BlacklistStep.cs index 47864f7917e..670fa04c661 100644 --- a/mcs/tools/linker/Mono.Linker.Steps/BlacklistStep.cs +++ b/mcs/tools/linker/Mono.Linker.Steps/BlacklistStep.cs @@ -26,9 +26,11 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // +using System; using System.Linq; using System.IO; using System.Reflection; +using System.Xml; using System.Xml.XPath; using Mono.Cecil; @@ -55,9 +57,19 @@ namespace Mono.Linker.Steps { .SelectMany (asm => asm.Modules) .SelectMany (mod => mod.Resources) .Where (res => res.ResourceType == ResourceType.Embedded) + .Where (res => Path.GetExtension (res.Name) == ".xml") .Where (res => IsReferenced (GetAssemblyName (res.Name))) .Cast ()) { - Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetExternalResolveStep (rsc)); + try { + if (Context.LogInternalExceptions) + Console.WriteLine ("Processing embedded resource linker descriptor: {0}", rsc.Name); + + Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetExternalResolveStep (rsc)); + } catch (XmlException ex) { + /* This could happen if some broken XML file is embedded. */ + if (Context.LogInternalExceptions) + Console.WriteLine ("Error processing {0}: {1}", rsc.Name, ex); + } } } diff --git a/mcs/tools/linker/Mono.Linker/LinkContext.cs b/mcs/tools/linker/Mono.Linker/LinkContext.cs index c4d71083cd5..417206ce079 100644 --- a/mcs/tools/linker/Mono.Linker/LinkContext.cs +++ b/mcs/tools/linker/Mono.Linker/LinkContext.cs @@ -93,6 +93,8 @@ namespace Mono.Linker { set { _symbolWriterProvider = value; } } + public bool LogInternalExceptions { get; set; } = false; + public LinkContext (Pipeline pipeline) : this (pipeline, new AssemblyResolver ()) { -- 2.25.1