Class: Contrast::Agent::Assess::PreShift

Inherits:
Object
  • Object
show all
Extended by:
Components::Logger::InstanceMethods
Includes:
Components::Logger::InstanceMethods
Defined in:
lib/contrast/agent/assess/policy/preshift.rb,
ext/cs__contrast_patch/cs__contrast_patch.c

Overview

In order to properly shift tags to account for the changes this method caused, we’ll need to store the state before the change occurred.

Constant Summary collapse

UNDUPLICABLE_MODULES =

rubocop: disable Style/MutableConstant

[ # rubocop: disable Style/MutableConstant
  Enumerator # dup'ing results in 'can't copy execution context'
]

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Components::Logger::InstanceMethods

cef_logger, logger

Instance Attribute Details

#arg_lengthsArray<Integer>

Returns the lengths of the arguments to be passed to.

Returns:

  • (Array<Integer>)

    the lengths of the arguments to be passed to



32
33
34
# File 'lib/contrast/agent/assess/policy/preshift.rb', line 32

def arg_lengths
  @arg_lengths
end

#argsArray<Object>

Returns the arguments to be passed to the method.

Returns:

  • (Array<Object>)

    the arguments to be passed to the method.



30
31
32
# File 'lib/contrast/agent/assess/policy/preshift.rb', line 30

def args
  @args
end

#objectObject

Returns the object on which the method is to be called.

Returns:

  • (Object)

    the object on which the method is to be called.



25
26
27
# File 'lib/contrast/agent/assess/policy/preshift.rb', line 25

def object
  @object
end

#object_lengthInteger

Returns the length of the object on which the method is to be called.

Returns:

  • (Integer)

    the length of the object on which the method is to be called.



28
29
30
# File 'lib/contrast/agent/assess/policy/preshift.rb', line 28

def object_length
  @object_length
end

Class Method Details

.build_preshift(propagation_node, object, args) ⇒ Contrast::Agent::Assess::PreShift?

Save the state before we do the propagation. This is one of the few things that we’ll call BEFORE calling the original method. Unfortunately, we may waste some time here if the method then throws an exception, but hey, it threw an exception. These few extra objects aren’t the real problem in that case.

Parameters:

Returns:

  • (Contrast::Agent::Assess::PreShift, nil)

    a holder saving the state of the object and arguments just prior to the method being called or nil if one is not required.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/contrast/agent/assess/policy/preshift.rb', line 51

def build_preshift propagation_node, object, args
  return unless propagation_node
  return unless ::Contrast::ASSESS.enabled?

  # don't do preshift just use the original object
  return if propagation_node.use_original_object?

  initializing = propagation_node.method_name == :initialize
  return if unsafe_io_object?(object, initializing)

  needs_object = propagation_node.needs_object?
  needs_args = propagation_node.needs_args?

  preshift = Contrast::Agent::Assess::PreShift.new
  append_object_details(preshift, initializing, object) if needs_object
  append_arg_details(preshift, args) if needs_args

  preshift
rescue StandardError => e
  logger.error('Unable to build preshift for method.', e)
  nil
end