From f076746dd7ebaca8ae9c772b3607e3e218bb6d88 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 5 Feb 2015 13:43:14 -0500 Subject: [PATCH] [Microsoft.Build.Utilities] Fixed MSBuildErrorParser to be more robust --- .../MSBuildErrorParser.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/MSBuildErrorParser.cs b/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/MSBuildErrorParser.cs index 60f3e7f7097..b536461242e 100644 --- a/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/MSBuildErrorParser.cs +++ b/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/MSBuildErrorParser.cs @@ -59,15 +59,31 @@ namespace Microsoft.Build.Utilities // public static Result TryParseLine (string line) { + int originEnd, originStart = 0; var result = new Result (); - int originStart = 0; MoveNextNonSpace (line, ref originStart); + if (originStart >= line.Length) + return null; + //find the origin section //the filename may include a colon for Windows drive e.g. C:\foo, so ignore colon in first 2 chars - int originEnd = line[originStart] == ':'? originStart : line.IndexOf (':', originStart + 2) - 1; + if (line[originStart] != ':') { + if (originStart + 2 >= line.Length) + return null; + + if ((originEnd = line.IndexOf (':', originStart + 2) - 1) < 0) + return null; + } else { + originEnd = originStart; + } + int categoryStart = originEnd + 2; + + if (categoryStart >= line.Length) + return null; + MovePrevNonSpace (line, ref originEnd); //if there is no origin section, then we can't parse the message @@ -76,8 +92,13 @@ namespace Microsoft.Build.Utilities //find the category section, if there is one MoveNextNonSpace (line, ref categoryStart); + + if (categoryStart >= line.Length) + return null; + int categoryEnd = line.IndexOf (':', categoryStart) - 1; int messageStart = categoryEnd + 2; + if (categoryEnd >= 0) { MovePrevNonSpace (line, ref categoryEnd); if (categoryEnd <= categoryStart) -- 2.25.1