Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Build/Construction/Solution/ProjectInSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,11 @@ internal bool CanBeMSBuildProjectFile(out string errorMessage)
try
{
// Read project thru a XmlReader with proper setting to avoid DTD processing
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
var projectDocument = new XmlDocument();

using (XmlReader xmlReader = XmlReader.Create(AbsolutePath, xrSettings))
FileStream fs = File.OpenRead(AbsolutePath);
using (XmlReader xmlReader = XmlReader.Create(fs, xrSettings))
{
// Load the project file and get the first node
projectDocument.Load(xmlReader);
Expand Down
5 changes: 3 additions & 2 deletions src/Build/Construction/Solution/SolutionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,11 @@ internal void ParseEtpProject(ProjectInSolution etpProj)
*</EFPROJECT>
**********************************************************************************/
// Make sure the XML reader ignores DTD processing
var readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
var readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };

// Load the .etp project file thru the XML reader
using (XmlReader xmlReader = XmlReader.Create(fullPathToEtpProj, readerSettings))
FileStream fs = File.OpenRead(fullPathToEtpProj);
using (XmlReader xmlReader = XmlReader.Create(fs, readerSettings))
{
etpProjectDocument.Load(xmlReader);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Tasks/AppConfig/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ internal sealed class AppConfig
/// <summary>
/// Read the .config from a file.
/// </summary>
/// <param name="appConfigFile"></param>
internal void Load(string appConfigFile)
/// <param name="appConfigFilePath"></param>
internal void Load(string appConfigFilePath)
{
XmlReader reader = null;
try
Expand All @@ -29,11 +29,11 @@ internal void Load(string appConfigFile)

// it's important to normalize the path as it may contain two slashes
// see https://github.com/dotnet/msbuild/issues/4335 for details.
appConfigFile = FileUtilities.NormalizePath(appConfigFile);
appConfigFilePath = FileUtilities.NormalizePath(appConfigFilePath);

// Need a filestream as the XmlReader doesn't support nonstandard unicode characters in path.
// No need to dispose - as 'CloseInput' was passed to XmlReaderSettings
FileStream fs = File.OpenRead(appConfigFile);
FileStream fs = File.OpenRead(appConfigFilePath);
reader = XmlReader.Create(fs, readerSettings);
Read(reader);
}
Expand All @@ -48,7 +48,7 @@ internal void Load(string appConfigFile)
linePosition = info.LinePosition;
}

throw new AppConfigException(e.Message, appConfigFile, lineNumber, linePosition, e);
throw new AppConfigException(e.Message, appConfigFilePath, lineNumber, linePosition, e);
}
catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
{
Expand All @@ -61,7 +61,7 @@ internal void Load(string appConfigFile)
linePosition = info.LinePosition;
}

throw new AppConfigException(e.Message, appConfigFile, lineNumber, linePosition, e);
throw new AppConfigException(e.Message, appConfigFilePath, lineNumber, linePosition, e);
}
finally
{
Expand Down
14 changes: 8 additions & 6 deletions src/Tasks/BootstrapperUtil/BootstrapperBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,15 @@ private void RefreshResources()
foreach (string subDirectory in Directory.GetDirectories(startDirectory))
{
string resourceDirectory = System.IO.Path.Combine(startDirectory, subDirectory);
string resourceFile = System.IO.Path.Combine(resourceDirectory, SETUP_RESOURCES_FILE);
if (FileSystems.Default.FileExists(resourceFile))
string resourceFilePath = System.IO.Path.Combine(resourceDirectory, SETUP_RESOURCES_FILE);
if (FileSystems.Default.FileExists(resourceFilePath))
{
var resourceDoc = new XmlDocument();
try
{
var xrs = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
using (var xr = XmlReader.Create(resourceFile, xrs))
var xrs = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(resourceFilePath);
using (var xr = XmlReader.Create(fs, xrs))
{
resourceDoc.Load(xr);
}
Expand Down Expand Up @@ -836,8 +837,9 @@ private XmlDocument LoadAndValidateXmlDocument(string filePath, bool validateFil
#pragma warning disable 618 // Using XmlValidatingReader. TODO: We need to switch to using XmlReader.Create() with validation.
var validatingReader = new XmlValidatingReader(xmlReader);
#pragma warning restore 618
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
using (XmlReader xr = XmlReader.Create(schemaPath, xrSettings))
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(schemaPath);
using (XmlReader xr = XmlReader.Create(fs, xrSettings))
{
try
{
Expand Down
5 changes: 3 additions & 2 deletions src/Tasks/ManifestUtil/ApplicationManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,9 @@ private void ValidateConfig()
if (!TrustInfo.IsFullTrust)
{
var document = new XmlDocument();
var xrs = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
using (XmlReader xr = XmlReader.Create(configFile.ResolvedPath, xrs))
var xrs = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(configFile.ResolvedPath);
using (XmlReader xr = XmlReader.Create(fs, xrs))
{
document.Load(xr);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Tasks/ManifestUtil/AssemblyIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ public static AssemblyIdentity FromManifest(string path)
var document = new XmlDocument();
try
{
var readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
using (XmlReader xmlReader = XmlReader.Create(path, readerSettings))
var readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(path);
using (XmlReader xmlReader = XmlReader.Create(fs, readerSettings))
{
document.Load(xmlReader);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Tasks/ManifestUtil/DeployManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ private static string GetInstallableFramework(string redistListFilePath)
try
{
var doc = new XmlDocument();
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
using (XmlReader xr = XmlReader.Create(redistListFilePath, xrSettings))
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(redistListFilePath);
using (XmlReader xr = XmlReader.Create(fs, xrSettings))
{
doc.Load(xr);
XmlNode fileListNode = doc.DocumentElement;
Expand Down
5 changes: 3 additions & 2 deletions src/Tasks/ManifestUtil/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,9 @@ internal bool TreatUnfoundNativeAssembliesAsPrerequisites
internal static void UpdateEntryPoint(string inputPath, string outputPath, string updatedApplicationPath, string applicationManifestPath, string targetFrameworkVersion)
{
var document = new XmlDocument();
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
using (XmlReader xr = XmlReader.Create(inputPath, xrSettings))
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(inputPath);
using (XmlReader xr = XmlReader.Create(fs, xrSettings))
{
document.Load(xr);
}
Expand Down
16 changes: 9 additions & 7 deletions src/Tasks/ManifestUtil/ManifestReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ private static XmlDocument GetXmlDocument(string path)
// if first two bytes are "MZ" then we're looking at an .exe or a .dll not a .manifest
if ((buffer[0] == 0x4D) && (buffer[1] == 0x5A))
{
Stream m = EmbeddedManifestReader.Read(path);
if (m == null)
using (Stream m = EmbeddedManifestReader.Read(path))
{
throw new BadImageFormatException(null, path);
}
if (m == null)
{
throw new BadImageFormatException(null, path);
}

using (XmlReader xr = XmlReader.Create(m, xrSettings))
{
document.Load(xr);
using (XmlReader xr = XmlReader.Create(m, xrSettings))
{
document.Load(xr);
}
}
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/Tasks/ManifestUtil/SecurityUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,10 @@ private static void SignFileInternal(X509Certificate2 cert,
try
{
var doc = new XmlDocument { PreserveWhitespace = true };
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
using (XmlReader xr = XmlReader.Create(path, xrSettings))
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(path);

using (XmlReader xr = XmlReader.Create(fs, xrSettings))
{
doc.Load(xr);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Tasks/RedistList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,10 @@ internal static string ReadFile(AssemblyTableInfo assemblyTableInfo, List<Assemb

try
{
var readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
reader = XmlReader.Create(path, readerSettings);
var readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(path);

reader = XmlReader.Create(fs, readerSettings);

while (reader.Read())
{
Expand Down
5 changes: 3 additions & 2 deletions src/Utilities/PlatformManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ private void LoadManifestFile()
if (FileSystems.Default.FileExists(platformManifestPath))
{
XmlDocument doc = new XmlDocument();
XmlReaderSettings readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
XmlReaderSettings readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };

using (XmlReader xmlReader = XmlReader.Create(platformManifestPath, readerSettings))
FileStream fs = File.OpenRead(platformManifestPath);
using (XmlReader xmlReader = XmlReader.Create(fs, readerSettings))
{
doc.Load(xmlReader);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Utilities/SDKManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ private void LoadManifestFile()
if (FileSystems.Default.FileExists(sdkManifestPath))
{
XmlDocument doc = new XmlDocument();
XmlReaderSettings readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
XmlReaderSettings readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };

using (XmlReader xmlReader = XmlReader.Create(sdkManifestPath, readerSettings))
FileStream fs = File.OpenRead(sdkManifestPath);
using (XmlReader xmlReader = XmlReader.Create(fs, readerSettings))
{
doc.Load(xmlReader);
}
Expand Down
15 changes: 7 additions & 8 deletions src/Utilities/ToolLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3116,10 +3116,10 @@ internal static string ChainReferenceAssemblyPath(string targetFrameworkDirector

// Make sure we have a directory with a redist list folder and a FrameworkList.xml file in there as this is what we will use for chaining.
string redistListFolder = Path.Combine(path, "RedistList");
string redistFile = Path.Combine(redistListFolder, "FrameworkList.xml");
string redistFilePath = Path.Combine(redistListFolder, "FrameworkList.xml");

// If the redist list does not exist then the entire chain is incorrect.
if (!FileSystems.Default.FileExists(redistFile))
if (!FileSystems.Default.FileExists(redistFilePath))
{
// Under MONO a directory may chain to one that has no redist list
var chainReference = NativeMethodsShared.IsMono ? string.Empty : null;
Expand All @@ -3139,10 +3139,9 @@ internal static string ChainReferenceAssemblyPath(string targetFrameworkDirector
try
{
// Read in the xml file looking for the includeFramework inorder to chain.
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.DtdProcessing = DtdProcessing.Ignore;

using (XmlReader reader = XmlReader.Create(redistFile, readerSettings))
XmlReaderSettings readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(redistFilePath);
using (XmlReader reader = XmlReader.Create(fs, readerSettings))
{
while (reader.Read())
{
Expand Down Expand Up @@ -3182,11 +3181,11 @@ internal static string ChainReferenceAssemblyPath(string targetFrameworkDirector
}
catch (XmlException ex)
{
ErrorUtilities.ThrowInvalidOperation("ToolsLocationHelper.InvalidRedistFile", redistFile, ex.Message);
ErrorUtilities.ThrowInvalidOperation("ToolsLocationHelper.InvalidRedistFile", redistFilePath, ex.Message);
}
catch (Exception ex) when (ExceptionHandling.IsIoRelatedException(ex))
{
ErrorUtilities.ThrowInvalidOperation("ToolsLocationHelper.InvalidRedistFile", redistFile, ex.Message);
ErrorUtilities.ThrowInvalidOperation("ToolsLocationHelper.InvalidRedistFile", redistFilePath, ex.Message);
}

// Cache the display name if we have one
Expand Down