Module: Contrast::Extension::Assess::KernelPropagator

Extended by:
Components::Logger::InstanceMethods, ExecTrigger
Defined in:
lib/contrast/extension/assess/kernel.rb,
ext/cs__assess_kernel/cs__assess_kernel.c

Overview

This module provides us with a way to invoke Kernel propagation for those methods which are too complex to fit into one of the standard Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the Kernel Module or exposing our methods there.

Class Method Summary collapse

Methods included from ExecTrigger

apply_trigger

Methods included from Components::Logger::InstanceMethods

cef_logger, logger

Class Method Details

.sprintf_tagger(patcher, preshift, ret, _block) ⇒ Object

We’re ‘tracking’ sprintf now, meaning if anything is tracked on the way in, the entire result will be tracked out. We’re going to take this approach for now b/c it’s fast and easy. I don’t super love it, and by that I mean I hate it.

To actually track this, we’d have to find the index of the new things being added, then remove the tags at the range of the format marker, which is some arbitrary length thing, and add the new tags from the inserted string, shifted down by the length of the aforementioned marker.

marker is in the format %[flags][.precision]type, type being a single character. We could regexp this with %.+[bBdiouxXeEfgGaAcps%]

also, b/c Ruby hates us, there are things called absolute markers, (digit)$, that go in the flags section. These cannot be mixed w/ the order assumed type

oh, and there’s also %<name>type and %name… b/c of course there is -HM



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/contrast/extension/assess/kernel.rb', line 42

def sprintf_tagger patcher, preshift, ret, _block
  return unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))

  format_string = preshift.args[0]
  args = preshift.args[1]

  parent_events = []
  track_sprintf(ret, format_string, args, parent_events)
  event_data = Contrast::Agent::Assess::Events::EventData.new(patcher,
                                                              ret,
                                                              preshift.object,
                                                              ret,
                                                              preshift.args)
  properties.build_event(event_data, 1)

  properties.event.instance_variable_set(:@_parent_events, parent_events)
  ret
end

.track_sprintf(result, format_string, args, parent_events) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/contrast/extension/assess/kernel.rb', line 61

def track_sprintf result, format_string, args, parent_events
  handle_sprintf_value(format_string, result, parent_events)
  case args
  when String
    handle_sprintf_value(args, result, parent_events)
  when Hash
    handle_sprintf_hash(args, result, parent_events)
  when Array
    handle_sprintf_array(args, result, parent_events)
  end
rescue StandardError => e
  logger.error('Unable to track dataflow through sprintf', e)
end