Class: RemLint::Rules::ShellUseWhileRunDisabled

Inherits:
RemLint::Rule show all
Defined in:
lib/remlint/rules/shell_use_while_run_disabled.rb

Overview

A function that shells out, defined while RUN is off.

Remind binds the RUN permission when a function is defined, not when it is called. userfns.c stores the flag on the function (if (RunDisabled) func->run_disabled = 1) and expr.c puts it back on every call (if (f->run_disabled) RunDisabled |= RUN_UF). So:

RUN OFF
FSET listing() shell("ls")
RUN ON
MSG [listing()]           # RUN disabled

The function is defined in the sandbox and stays in it for good. Nothing about the definition looks wrong, the RUN ON above the call looks like it should be enough, and the error arrives from the call site -- which is the one place the mistake is not.

shell() is the only builtin that needs the permission (funcs.c:2545); INCLUDECMD needs it too but is a command, not something a function can contain.

Constant Summary collapse

SHELL =
"shell"
ON =
"ON"
OFF =
"OFF"

Constants inherited from RemLint::Rule

RemLint::Rule::REGISTRY

Instance Attribute Summary

Attributes inherited from RemLint::Rule

#config, #document, #offenses

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemLint::Rule

all, enabled_by_default?, find, inherited, #initialize, rule_name, #rule_name, #run

Constructor Details

This class inherits a constructor from RemLint::Rule

Class Method Details

.default_severityObject



33
34
35
# File 'lib/remlint/rules/shell_use_while_run_disabled.rb', line 33

def self.default_severity
  "error"
end

.descriptionObject



37
38
39
# File 'lib/remlint/rules/shell_use_while_run_disabled.rb', line 37

def self.description
  "A function calling shell(), defined between RUN OFF and RUN ON."
end

Instance Method Details

#checkObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/remlint/rules/shell_use_while_run_disabled.rb', line 41

def check
  disabled = false

  document.code_commands.each do |command|
    directive = run_directive(command)

    if directive
      disabled = directive == OFF
    elsif disabled
      check_definition(command)
    end
  end
end