Class: Pedant::CheckGetByteUsed

Inherits:
Check
  • Object
show all
Defined in:
lib/pedant/checks/get_byte_used.rb

Instance Attribute Summary

Attributes inherited from Check

#result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Check

all, depends, #fail, #fatal, friendly_name, inherited, #initialize, initialize!, list, #pass, provides, ready?, #report, run_checks_in_dependency_order, #skip, #warn

Constructor Details

This class inherits a constructor from Pedant::Check

Class Method Details

.requiresObject



29
30
31
# File 'lib/pedant/checks/get_byte_used.rb', line 29

def self.requires
  super + [:main, :trees]
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pedant/checks/get_byte_used.rb', line 33

def run
  # This check only applies to plugins.
  return skip unless @kb[:main].extname == '.nasl'

  tree = @kb[:trees][@kb[:main]]

  tree.all(:Call).each do |node|
    next unless [
      "get_byte",
      "get_word",
      "get_dword"
    ].include? node.name.ident.name

    # error if we are also using set_byte_order()
    if tree.all(:Call).any? { |node2| node2.name.ident.name == "set_byte_order" }
      report(:error, "Plugin is using #{node.name.ident.name}(), which does not respect set_byte_order(). Since this plugin also uses set_byte_order(), we should be using the set_byte_order() respecting function #{node.name.ident.name.tr("_","")}() from byte_func.inc instead, as #{node.name.ident.name}() will always operate as if the byte order is set to little endian.")
      report(:error, node.context())
      return fail
    end

    # just warn otherwise
    report(:warn, "Plugin is using #{node.name.ident.name}(), which does not respect set_byte_order(). Consider using the set_byte_order() respecting function #{node.name.ident.name.tr("_","")}() from byte_func.inc instead, as #{node.name.ident.name}() will always operate as if the byte order is set to little endian.")
    report(:warn, node.context())
    return fail
  end
  report(:info, "Plugin is not using any of get_byte(), get_word(), or get_dword(), which can be problematic as they do not respect set_byte_order().")
  pass
end