-
Notifications
You must be signed in to change notification settings - Fork 106
Expose policy governance APIs #1402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 2 commits
51f3239
c9c9565
65a7e85
0412a3e
5c50e2b
abdeae7
d9deacf
e49cb27
3b20a73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| using Neo.SmartContract.Testing.Coverage; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
|
|
||
|
|
@@ -28,8 +29,6 @@ public class WriteInTryVulnerability | |
| // key block writes storage; value blocks in try | ||
| public readonly Dictionary<BasicBlock, HashSet<int>> vulnerabilities; | ||
| public JToken? DebugInfo { get; init; } | ||
| // TODO: use debugInfo to GetWarningInfo with source codes | ||
|
|
||
| public WriteInTryVulnerability(Dictionary<BasicBlock, HashSet<int>> vulnerabilities, JToken? debugInfo = null) | ||
| { | ||
| this.vulnerabilities = vulnerabilities; | ||
|
|
@@ -211,19 +210,45 @@ private class SourceLocation | |
| if (sequencePoint.Document >= 0 && sequencePoint.Document < debugInfo.Documents.Count) | ||
| { | ||
| var fileName = debugInfo.Documents[sequencePoint.Document]; | ||
| var snippet = TryGetSourceLine(fileName, sequencePoint.Start.Line); | ||
| return new SourceLocation | ||
| { | ||
| FileName = System.IO.Path.GetFileName(fileName), | ||
| Line = sequencePoint.Start.Line, | ||
| Column = sequencePoint.Start.Column, | ||
| CodeSnippet = null // Could be enhanced to read actual source code | ||
| CodeSnippet = snippet | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private static string? TryGetSourceLine(string fileName, int zeroBasedLineNumber) | ||
| { | ||
| string? path = fileName; | ||
| if (!Path.IsPathRooted(path)) | ||
| path = Path.Combine(Environment.CurrentDirectory, path); | ||
|
|
||
| try | ||
| { | ||
| if (path != null && File.Exists(path)) | ||
|
||
| { | ||
| string[] lines = File.ReadAllLines(path); | ||
| foreach (int candidate in new[] { zeroBasedLineNumber, zeroBasedLineNumber - 1 }) | ||
| { | ||
| if (candidate >= 0 && candidate < lines.Length) | ||
| return lines[candidate].Trim(); | ||
| } | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| // ignore IO failures, diagnostics will fall back to instruction offsets | ||
| } | ||
shargon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return null; | ||
| } | ||
|
|
||
| public static HashSet<BasicBlock> FindAllBasicBlocksWritingStorageInTryCatchFinally | ||
| (TryCatchFinallySingleCoverage c, HashSet<TryCatchFinallySingleCoverage> visitedTrys, HashSet<BasicBlock> allBasicBlocksWritingStorage) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a part of 'Expose policy governance APIs' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, this pr focus on only exposing poliocy govergance API now