Module: Contrast::Extension::Assess::ContrastKernel

Defined in:
lib/contrast/extension/assess/kernel.rb

Overview

Used for Kernel exec aliasing since we have no other way of accessing the Kernel#exec under C if we alias it there.

Instance Method Summary collapse

Instance Method Details

#cs__kernel_exec(source) ⇒ Object

Method to replace the call to Kernel#exec when applying alias patch. It will invoke Contrast::Extension::Assess::KernelPropagator before calling the original method.

Parameters:

  • source (String, Proc)

    Potentially untrusted shell command to execute.

Returns:

  • nil - This method will invoke the Kernel#exec which will



111
112
113
114
115
116
117
118
119
120
# File 'lib/contrast/extension/assess/kernel.rb', line 111

def cs__kernel_exec source
  # Check if in contrast scope and we have source.
  unless Contrast::Agent::Patching::Policy::Patch.in_contrast_scope? || source.nil?
    Contrast::Agent::Patching::Policy::Patch.with_contrast_scope do
      Contrast::Extension::Assess::KernelPropagator.apply_trigger(source)
    end
  end
  # Call this in the end else any code bellow this call won't be executed.
  Kernel.exec(source)
end