Class: Brakeman::FindAllCalls

Inherits:
BaseProcessor show all
Defined in:
lib/brakeman/processors/lib/find_all_calls.rb

Constant Summary

Constants included from Util

Util::ALL_PARAMETERS, Util::COOKIES, Util::PARAMETERS, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary collapse

Attributes inherited from BaseProcessor

#ignore

Attributes inherited from SexpProcessor

#context, #env, #expected

Instance Method Summary collapse

Methods inherited from BaseProcessor

#find_render_type, #make_render, #make_render_in_view, #process_arglist, #process_block, #process_class, #process_default, #process_dstr, #process_evstr, #process_hash, #process_if, #process_ignore, #process_iter, #process_lasgn, #process_scope

Methods included from Util

#array?, #call?, #camelize, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #node_type?, #number?, #params?, #pluralize, #regexp?, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #true?, #truncate_table, #underscore

Methods included from ProcessorHelper

#class_name, #process_all, #process_module

Methods inherited from SexpProcessor

#error_handler, #in_context, #process, #process_dummy, #scope

Constructor Details

#initialize(tracker) ⇒ FindAllCalls

Returns a new instance of FindAllCalls.



6
7
8
9
10
11
12
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 6

def initialize tracker
  super
  @current_class = nil
  @current_method = nil
  @in_target = false
  @calls = []
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



4
5
6
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 4

def calls
  @calls
end

Instance Method Details

#process_attrasgn(exp) ⇒ Object

Process an assignment like a call



101
102
103
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 101

def process_attrasgn exp
  process_call exp
end

#process_call(exp) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 38

def process_call exp
  target = get_target exp.target
  
  if call? target
    already_in_target = @in_target
    @in_target = true
    process target
    @in_target = already_in_target
  end

  method = exp.method
  process_all exp.args

  call = { :target => target, :method => method, :call => exp, :nested => @in_target, :chain => get_chain(exp) }
  
  if @current_template
    call[:location] = [:template, @current_template]
  else
    call[:location] = [:class, @current_class, @current_method]
  end

  @calls << call

  exp
end

#process_dxstr(exp) ⇒ Object

Technically, “ is call to Kernel#‘ But we just need them in the call cache for speed



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 84

def process_dxstr exp
  process exp.last if sexp? exp.last

  call = { :target => nil, :method => :`, :call => exp, :nested => false }

  if @current_template
    call[:location] = [:template, @current_template]
  else
    call[:location] = [:class, @current_class, @current_method]
  end

  @calls << call

  exp
end

#process_methdef(exp) ⇒ Object

Process body of method



24
25
26
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 24

def process_methdef exp
  process exp.body
end

#process_render(exp) ⇒ Object

Calls to render() are converted to s(:render, …) but we would like them in the call cache still for speed



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 66

def process_render exp
  process exp.last if sexp? exp.last

  call = { :target => nil, :method => :render, :call => exp, :nested => false }

  if @current_template
    call[:location] = [:template, @current_template]
  else
    call[:location] = [:class, @current_class, @current_method]
  end

  @calls << call

  exp
end

#process_rlist(exp) ⇒ Object

Process body of block



34
35
36
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 34

def process_rlist exp
  process_all exp
end

#process_selfdef(exp) ⇒ Object

Process body of method



29
30
31
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 29

def process_selfdef exp
  process exp.body
end

#process_source(exp, klass = nil, method = nil, template = nil) ⇒ Object

Process the given source. Provide either class and method being searched or the template. These names are used when reporting results.



16
17
18
19
20
21
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 16

def process_source exp, klass = nil, method = nil, template = nil
  @current_class = klass
  @current_method = method
  @current_template = template
  process exp
end