public RuleResult CheckMethod (MethodDefinition method) { // rule only applies to methods with IL and exceptions handlers if (!method.HasBody) return RuleResult.DoesNotApply; MethodBody body = method.Body; if (!body.HasExceptionHandlers) return RuleResult.DoesNotApply; // and when the IL contains a Throw instruction (Rethrow is fine) if (!OpCodeEngine.GetBitmask (method).Get (Code.Throw)) return RuleResult.DoesNotApply; warned_offsets_in_method.Clear (); ExecutionPathFactory epf = new ExecutionPathFactory (); foreach (ExceptionHandler eh in body.ExceptionHandlers) { if (eh.HandlerType != ExceptionHandlerType.Catch) continue; var list = epf.CreatePaths (eh.HandlerStart, eh.HandlerEnd); if (list.Count == 0) { Runner.Report (method, eh.HandlerStart, Severity.Medium, Confidence.Normal, "Handler too complex for analysis"); } else { foreach (ExecutionPathCollection catchPath in list) ProcessCatchPath (catchPath, method); } } return Runner.CurrentRuleResult; }
public RuleResult CheckMethod (MethodDefinition method) { // rule only applies to methods with IL and exceptions handlers if (!method.HasBody || !method.Body.HasExceptionHandlers) return RuleResult.DoesNotApply; // and when the IL contains a Throw instruction (Rethrow is fine) if (!OpCodeEngine.GetBitmask (method).Get (Code.Throw)) return RuleResult.DoesNotApply; warned_offsets_in_method.Clear (); ExecutionPathFactory epf = new ExecutionPathFactory (); foreach (ExceptionHandler eh in method.Body.ExceptionHandlers) { if (eh.HandlerType != ExceptionHandlerType.Catch) continue; foreach (ExecutionPathCollection catchPath in epf.CreatePaths (eh.HandlerStart, eh.HandlerEnd)) { ProcessCatchPath (catchPath, method); } } return Runner.CurrentRuleResult; }
private void Branches (MethodDefinition method) { ExecutionPathFactory epf = new ExecutionPathFactory (); foreach (ExceptionHandler eh in method.Body.ExceptionHandlers) { if (eh.HandlerType != ExceptionHandlerType.Catch) continue; var list = epf.CreatePaths (eh.HandlerStart, eh.HandlerEnd); if (list.Count == 0) { Runner.Report (method, eh.HandlerStart, Severity.Medium, Confidence.Normal, "Handler too complex for analysis"); } else { foreach (ExecutionPathCollection catchPath in list) ProcessCatchPath (catchPath, method); } } }