class Pedant::CheckGetByteUsed

Public Class Methods

requires() click to toggle source
Calls superclass method Pedant::Check::requires
# File lib/pedant/checks/get_byte_used.rb, line 29
def self.requires
  super + [:main, :trees]
end

Public Instance Methods

run() click to toggle source
# 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