Skip to content

Commit

Permalink
Fix #1530: CS converter doesn't produce threadFlowLocation.location. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Larry Golding committed Jun 14, 2019
1 parent 76d4cf5 commit 7f9a558
Show file tree
Hide file tree
Showing 2 changed files with 489 additions and 94 deletions.
42 changes: 26 additions & 16 deletions src/Sarif.Converters/ContrastSecurityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,14 +1121,6 @@ private PhysicalLocation CreatePhysicalLocation(string uri, Region region = null
};
}

private static readonly Regex LogicalLocationRegex =
new Regex(
@"
([^\s]*\s+)? # Skip over an optional leading blank-terminated return type name such as 'void '
(?<fqln>[^(]+) # Take everything up to the opening parenthesis.
",
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);

// Find the user code method call closest to the top of the stack. This is
// the location we should report as being responsible for the result.
private static string GetUserCodeLocation(Stack stack)
Expand All @@ -1138,14 +1130,9 @@ private static string GetUserCodeLocation(Stack stack)
foreach (StackFrame frame in stack.Frames)
{
string fullyQualifiedLogicalName = frame.Location.LogicalLocation.FullyQualifiedName;
Match match = LogicalLocationRegex.Match(fullyQualifiedLogicalName);
if (match.Success)
if (!fullyQualifiedLogicalName.StartsWith(SystemPrefix))
{
fullyQualifiedLogicalName = match.Groups["fqln"].Value;
if (!fullyQualifiedLogicalName.StartsWith(SystemPrefix))
{
return fullyQualifiedLogicalName;
}
return fullyQualifiedLogicalName;
}
}

Expand Down Expand Up @@ -1533,18 +1520,39 @@ private static void ReadSignature(SparseReader reader, object parent)

private static StackFrame CreateStackFrameFromSignature(string signature)
{
string signatureMinusReturnType = RemoveReturnTypeFrom(signature);

return new StackFrame
{
Location = new Location
{
LogicalLocation = new LogicalLocation
{
FullyQualifiedName = signature
FullyQualifiedName = signatureMinusReturnType
}
}
};
}

private static readonly Regex LogicalLocationRegex =
new Regex(
@"^
([^\s]*\s+)? # Skip over an optional leading blank-terminated return type name such as 'void '.
(?<fqln>.*) # Take everything else.
$",
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);

private static string RemoveReturnTypeFrom(string signature)
{
Match match = LogicalLocationRegex.Match(signature);
if (match.Success)
{
signature = match.Groups["fqln"].Value;
}

return signature;
}

private static void ReadObject(SparseReader reader, object parent)
{
reader.Skip();
Expand Down Expand Up @@ -1617,6 +1625,8 @@ private static void ReadStack(SparseReader reader, object parent)
Debug.Assert(context.CurrentThreadFlowLocation == null);
context.CurrentThreadFlowLocation = new ThreadFlowLocation
{
Location = context.Signature.Location,

Stack = new Stack
{
Frames = new List<StackFrame> { context.Signature }
Expand Down
Loading

0 comments on commit 7f9a558

Please sign in to comment.