rapid7/metasploit-framework

View on GitHub
lib/net/dns/resolver.rb

Summary

Maintainability
F
5 days
Test Coverage

File resolver.rb has 640 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'socket'
require 'timeout'
require 'ipaddr'
require 'logger'
require 'net/dns/packet'
Severity: Major
Found in lib/net/dns/resolver.rb - About 1 day to fix

    Class Resolver has 48 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Resolver
    
          class NextNameserver < RuntimeError
          end
    
    
    Severity: Minor
    Found in lib/net/dns/resolver.rb - About 6 hrs to fix

      Method send_tcp has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
      Open

            def send_tcp(packet,packet_data)
      
              ans = nil
              length = [packet_data.size].pack("n")
      
      
      Severity: Minor
      Found in lib/net/dns/resolver.rb - About 5 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method send has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

            def send(argument,type=Net::DNS::A,cls=Net::DNS::IN)
              if @config[:nameservers].size == 0
                raise ResolverError, "No nameservers specified!"
              end
      
      
      Severity: Minor
      Found in lib/net/dns/resolver.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method send_tcp has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def send_tcp(packet,packet_data)
      
              ans = nil
              length = [packet_data.size].pack("n")
      
      
      Severity: Major
      Found in lib/net/dns/resolver.rb - About 2 hrs to fix

        Method axfr has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

              def axfr(name,cls=Net::DNS::IN)
                @logger.info "Requested AXFR transfer, zone #{name} class #{cls}"
                if @config[:nameservers].size == 0
                  raise ResolverError, "No nameservers specified!"
                end
        Severity: Minor
        Found in lib/net/dns/resolver.rb - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method send has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def send(argument,type=Net::DNS::A,cls=Net::DNS::IN)
                if @config[:nameservers].size == 0
                  raise ResolverError, "No nameservers specified!"
                end
        
        
        Severity: Major
        Found in lib/net/dns/resolver.rb - About 2 hrs to fix

          Method axfr has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def axfr(name,cls=Net::DNS::IN)
                  @logger.info "Requested AXFR transfer, zone #{name} class #{cls}"
                  if @config[:nameservers].size == 0
                    raise ResolverError, "No nameservers specified!"
                  end
          Severity: Minor
          Found in lib/net/dns/resolver.rb - About 1 hr to fix

            Method make_query_packet has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                  def make_query_packet(string,type,cls)
                    case string
                    when IPAddr
                      name = string.reverse
                      type = Net::DNS::PTR
            Severity: Minor
            Found in lib/net/dns/resolver.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method nameservers= has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def nameservers=(arg)
                    case arg
                    when String
                      begin
                        @config[:nameservers] = [IPAddr.new(arg)]
            Severity: Minor
            Found in lib/net/dns/resolver.rb - About 1 hr to fix

              Method source_address= has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def source_address=(addr)
                      unless addr.respond_to? :to_s
                        raise ResolverArgumentError, "Wrong address argument #{addr}"
                      end
              
              
              Severity: Minor
              Found in lib/net/dns/resolver.rb - About 1 hr to fix

                Method parse_config_file has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                      def parse_config_file
                        if RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/
                          require 'win32/resolv'
                          arr = Win32::Resolv.get_resolv_info
                          self.domain = arr[0]
                Severity: Minor
                Found in lib/net/dns/resolver.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method initialize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                      def initialize(config = {})
                        raise ResolverArgumentError, "Argument has to be Hash" unless config.kind_of? Hash
                        # config.key_downcase!
                        @config = Defaults.merge config
                        @raw = false
                Severity: Minor
                Found in lib/net/dns/resolver.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method nameservers= has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                      def nameservers=(arg)
                        case arg
                        when String
                          begin
                            @config[:nameservers] = [IPAddr.new(arg)]
                Severity: Minor
                Found in lib/net/dns/resolver.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method search has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                      def search(name,type=Net::DNS::A,cls=Net::DNS::IN)
                
                        # If the name contains at least one dot then try it as is first.
                        if name.include? "."
                          @logger.debug "Search(#{name},#{Net::DNS::RR::Types.new(type)},#{Net::DNS::RR::Classes.new(cls)})"
                Severity: Minor
                Found in lib/net/dns/resolver.rb - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method parse_environment_variables has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                      def parse_environment_variables
                        if ENV['RES_NAMESERVERS']
                          self.nameservers = ENV['RES_NAMESERVERS'].split(" ")
                        end
                        if ENV['RES_SEARCHLIST']
                Severity: Minor
                Found in lib/net/dns/resolver.rb - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method source_address= has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                      def source_address=(addr)
                        unless addr.respond_to? :to_s
                          raise ResolverArgumentError, "Wrong address argument #{addr}"
                        end
                
                
                Severity: Minor
                Found in lib/net/dns/resolver.rb - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method send_udp has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                      def send_udp(packet,packet_data)
                        socket = UDPSocket.new
                        socket.bind(@config[:source_address].to_s,@config[:source_port])
                
                        ans = nil
                Severity: Minor
                Found in lib/net/dns/resolver.rb - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method state has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                      def state
                        str = ";; RESOLVER state:\n;; "
                        i = 1
                        @config.each do |key,val|
                          if key == :log_file or key == :config_file
                Severity: Minor
                Found in lib/net/dns/resolver.rb - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                        config.each do |key,val|
                          next if key == :log_file or key == :config_file
                          begin
                            eval "self.#{key.to_s} = val"
                          rescue NoMethodError
                Severity: Minor
                Found in lib/net/dns/resolver.rb and 1 other location - About 25 mins to fix
                lib/rex/proto/dns/resolver.rb on lines 78..83

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 30.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status