Beispiel #1
0
        private static PumaLog parseBuildWarnings(Options o)
        {
            PumaLog instancelog = new PumaLog();

            using (FileStream stream = new FileStream(o.BuildFile, FileMode.Open))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    string line = null;
                    while ((line = reader.ReadLine()) != null)
                    {
                        PumaLogEntry instance = parseWarning(line);
                        if (instance != null)
                        {
                            instancelog.Add(instance);
                        }
                    }

                    //Kill the stream
                    reader.Dispose();
                }

                //Kill the stream
                stream.Dispose();
            }

            return(instancelog);
        }
Beispiel #2
0
        private static PumaLogEntry parseNonCodeWarning(string[] values)
        {
            /* Example non-code warning
             * CSC : warning SEC0013: Pages ViewStateEncryptionMode disabled. C:\Jenkins\workspace\Phisherman\Phisherman.Web\Web.config(39): <pages> [C:\Jenkins\workspace\Phisherman\Phisherman.Web\Phisherman.Web.csproj]
             */
            PumaLogEntry i = new PumaLogEntry();

            //PART 2: Parse category
            Match mCategory = Regex.Match(values[1], _REGEX_PUMA_ERROR_CODE);

            if (mCategory.Success)
            {
                i.RuleId = mCategory.Value;
            }

            //PART 3: Parse message
            string[] messageMatches = Regex.Split(values[2], _REGEX_FULL_WIN_FILE_PATH, RegexOptions.IgnoreCase);
            if (messageMatches.Length > 0)
            {
                i.Message = messageMatches[0].Trim();
            }

            //PART 4: Parse project
            Match mProject = Regex.Match(values[3], _REGEX_FULL_WIN_FILE_PATH);

            if (mProject.Success)
            {
                i.Project = mProject.Value;
            }

            //PART 3 CONTINUED: Parse path and line number
            Match mFilePath = Regex.Match(values[2], _REGEX_FULL_WIN_FILE_PATH, RegexOptions.IgnoreCase);

            if (mFilePath.Success)
            {
                string path         = "";
                int    lineNumber   = 0;
                int    columnNumber = 0;
                if (parseVisualStudioPath(mFilePath.Value, out path, out lineNumber, out columnNumber))
                {
                    i.Path         = path;
                    i.LineNumber   = lineNumber;
                    i.ColumnNumber = columnNumber;
                }
            }

            //PART 3: FINAL: Make path relative to project root
            Match mProjectDir = Regex.Match(i.Project, _REGEX_WIN_DIRECTORY, RegexOptions.IgnoreCase);

            if (mProject.Success)
            {
                i.Path = i.Path.Replace(mProjectDir.Value, "");
            }

            return(i);
        }
Beispiel #3
0
        private static PumaLogEntry parseCodeWarning(string[] values)
        {
            /*
             * Example code warning
             * 1) Controllers\EmailTemplate\AttachmentService.cs(40,13): warning SEC0112: Unvalidated file paths are passed to a File API, which can allow unauthorized file system operations (e.g. read, write, delete) to be performed on unintended server files. [C:\Jenkins\workspace\Phisherman\Phisherman.Web\Phisherman.Web.csproj]
             */
            Match mLocalPath = Regex.Match(values[0], _REGEX_VS_RELATIVE_PATH);

            if (!mLocalPath.Success)
            {
                return(null);
            }

            PumaLogEntry i = new PumaLogEntry();

            //PART 1: Parse path, line, column from the local vs path
            string path         = "";
            int    lineNumber   = 0;
            int    columnNumber = 0;

            if (parseVisualStudioPath(mLocalPath.Value, out path, out lineNumber, out columnNumber))
            {
                i.Path         = path;
                i.LineNumber   = lineNumber;
                i.ColumnNumber = columnNumber;
            }

            //PART 2: Parse category
            Match mCategory = Regex.Match(values[1], _REGEX_PUMA_ERROR_CODE);

            if (mCategory.Success)
            {
                i.RuleId = mCategory.Value;
            }

            var mSeverity = Regex.Match(values[1], _REGEX_RULE_SEVERITY);

            if (mSeverity.Success)
            {
                i.RuleSeverity = mSeverity.Value;
            }

            //PART 3: Parse message and project
            string[] messages = values[2].Split(_VS_PROJECT_DELIMETER_OPEN);
            if (messages.Length != 2)
            {
                return(null);
            }

            i.Message = messages[0];
            i.Project = messages[1].TrimEnd(_VS_PROJECT_DELIMETER_CLOSE);
            return(i);
        }
Beispiel #4
0
        internal Result CreateResult(PumaLogEntry pumaLogEntry)
        {
            pumaLogEntry = pumaLogEntry ?? throw new ArgumentNullException(nameof(pumaLogEntry));

            Result result = new Result()
            {
                RuleId  = pumaLogEntry.RuleId,
                Message = new Message {
                    Text = pumaLogEntry.Message
                }
            };

            switch (pumaLogEntry.RuleSeverity.ToUpper())
            {
            case "ERROR":
                result.Level = ResultLevel.Error;
                break;

            case "WARN":
            case "WARNING":
                result.Level = ResultLevel.Warning;
                break;

            case "DEFAULT":
            default:
                result.Level = ResultLevel.Note;
                break;
            }
            result.Level = ResultLevel.Warning;

            Region region = new Region()
            {
                StartLine   = pumaLogEntry.LineNumber + 1,
                StartColumn = pumaLogEntry.ColumnNumber + 1,
            };

            Uri analysisTargetUri = new Uri(Path.Combine(Path.GetDirectoryName(pumaLogEntry.Project), pumaLogEntry.Path), UriKind.Relative);

            var      physicalLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: analysisTargetUri, uriBaseId: null), region: region, contextRegion: null);
            Location location         = new Location()
            {
                PhysicalLocation = physicalLocation
            };

            result.Locations = new List <Location>()
            {
                location
            };

            return(result);
        }
Beispiel #5
0
        private static PumaLogEntry parseWarning(string value)
        {
            //Cateogy must be for Puma (SEC####)
            if (!Regex.IsMatch(value, _REGEX_PUMA_CATEGORY))
            {
                return(null);
            }

            //Split the value on ": " to start processing
            string[] parts = Regex.Split(value, _REGEX_WARNING_DELIMITER);

            //Bail out if malformed
            if (parts.Length == 0 || parts.Length < 3)
            {
                return(null);
            }

            //Check the first part for a valid path (code warning) or missing data (non-code warning)
            Match        mLocalPath = Regex.Match(parts[0], _REGEX_VS_RELATIVE_PATH);
            PumaLogEntry i          = mLocalPath.Success ? parseCodeWarning(parts) : parseNonCodeWarning(parts);

            return(i);
        }
Beispiel #6
0
 private static string getBuildWarning(PumaLogEntry i)
 {
     return(string.Format(_MS_BUILD_WARNING_FORMAT, i.Path, i.LineNumber, i.ColumnNumber, i.RuleId, i.Message, i.Project));
 }