rapid7/ruby_smb

View on GitHub

Showing 174 of 307 total issues

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

      def read_and_return_value(io)
        max_length = eval_parameter(:max_length)
        if max_length && max_length % 2 != 0
          raise ArgumentError, "[Stringz16] #max_length should be a multiple of "\
            "two, since it is Unicode (got #{max_length})"
Severity: Minor
Found in lib/ruby_smb/field/stringz16.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 bytes_to_align has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def bytes_to_align(obj, rel_offset)
      if obj.is_a?(PointerPlugin)
        # Pointers are always 4-bytes aligned
        return (4 - (rel_offset % 4)) % 4
      end
Severity: Minor
Found in lib/ruby_smb/dcerpc/ndr.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 method_missing has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

            def method_missing(symbol, *args)
              # should we forward to one of the stat methods
              if STAT_METHODS.include?(symbol)
                # if we have a stat object then forward it
                return stat.send(symbol, *args) if exist?
Severity: Minor
Found in lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname.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 enum_registry_values has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def enum_registry_values(key, bind: true)
        bind(endpoint: RubySMB::Dcerpc::Winreg) if bind

        root_key, sub_key = key.gsub(/\//, '\\').split('\\', 2)
        root_key_handle = open_root_key(root_key)
Severity: Minor
Found in lib/ruby_smb/dcerpc/winreg.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 decrypt has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def decrypt(key, algorithm: 'AES-128-GCM')
          auth_data = self.to_binary_s[20...52]
          encrypted_data = self.encrypted_data.to_ary.pack('C*')

          case algorithm
Severity: Minor
Found in lib/ruby_smb/smb2/packet/transform_header.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 open_directory_packet has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def open_directory_packet(directory: nil, disposition: RubySMB::Dispositions::FILE_OPEN,
                                impersonation: RubySMB::ImpersonationLevels::SEC_IMPERSONATE,
                                read: true, write: false, delete: false, desired_delete: false)
        create_request = RubySMB::SMB2::Packet::CreateRequest.new
        create_request = set_header_fields(create_request)
Severity: Minor
Found in lib/ruby_smb/smb2/tree.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

Avoid too many return statements within this method.
Open

              return WindowsError::NTStatus::STATUS_LOGON_FAILURE
Severity: Major
Found in lib/ruby_smb/gss/provider/ntlm.rb - About 30 mins to fix

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

        def sum_num_bytes_below_index(index)
          (0...index).inject(0) do |sum, i|
            nbytes = 0
            if elements[i].has_parameter?(:byte_align) && elements[i].respond_to?(:bytes_to_align)
              nbytes = elements[i].bytes_to_align(elements[i], sum.ceil)
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/ndr.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 build has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.build(options)
            ntlm_provider = RubySMB::Gss::Provider::NTLM.new(
              allow_anonymous: options[:allow_anonymous],
              allow_guests: options[:allow_guests]
            )
    Severity: Minor
    Found in lib/ruby_smb/server/cli.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 children has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

                def children(with_directory=true)
                  raise Errno::ENOTDIR.new("Not a directory @ dir_initialize - #{to_s}") unless directory?
    
                  @virtual_disk.each_value.select { |dent| dent.dirname == self && dent != self }.map { |dent| with_directory ? dent : dent.basename }
                end
    Severity: Minor
    Found in lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname.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 trim_to! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def trim_to!(str, max_length = nil)
            if max_length
              max_length = 2 if max_length < 2
              str.slice!(max_length..-1)
              if str.length == max_length && str[-2, 2] != "\0\0"
    Severity: Minor
    Found in lib/ruby_smb/field/stringz16.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 method_missing has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.method_missing(symbol, *args, &block)
          field = super
          if field.is_a?(::Array) && field.last.is_a?(BinData::SanitizedField)
            unless field.last.has_parameter?(:byte_align) || field.last.instantiate.bit_aligned?
              raise ArgumentError.new(
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/ndr.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 query_value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def query_value(handle, value_name)
            query_value_request_packet = RubySMB::Dcerpc::Winreg::QueryValueRequest.new(hkey: handle, lp_value_name: value_name)
            query_value_request_packet.lp_type = 0
            query_value_request_packet.lpcb_data = 0
            query_value_request_packet.lpcb_len = 0
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/winreg.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 add_dynamic_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

              def add_dynamic_file(path, stat: nil, &block)
                raise ArgumentError.new('a block must be specified for dynamic files') unless block_given?
                path = VirtualPathname.cleanpath(path)
                path = File::SEPARATOR + path unless path.start_with?(File::SEPARATOR)
                raise ArgumentError.new('must be a file') if stat && !stat.file?
    Severity: Minor
    Found in lib/ruby_smb/server/share/provider/virtual_disk.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 smb3_decrypt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def smb3_decrypt(th)
            unless @server_encryption_key
              raise RubySMB::Error::EncryptionError.new('The encryption algorithm has not been set') if @encryption_algorithm.nil?
    
              key_bit_len = OpenSSL::Cipher.new(@encryption_algorithm).key_len * 8
    Severity: Minor
    Found in lib/ruby_smb/client/encryption.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 read has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.read(val)
          begin
            super(val)
          rescue IOError => e
            # $stderr.puts "#{e.class}: #{e.message}"
    Severity: Minor
    Found in lib/ruby_smb/generic_packet.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 bind has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def bind(options={})
          @call_id ||= 1
          bind_req = Bind.new(options)
          bind_req.pdu_header.call_id = @call_id
          auth_type = options.fetch(:auth_type) { RPC_C_AUTHN_WINNT }
    Severity: Minor
    Found in lib/ruby_smb/dcerpc.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 authenticate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def authenticate
            if smb1
              if username.empty? && password.empty?
                smb1_anonymous_auth
              else
    Severity: Minor
    Found in lib/ruby_smb/client/authentication.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 handle_smb1 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def handle_smb1(raw_request, header)
            session = @session_table[header.uid]
    
            if session.nil? && !(header.command == SMB1::Commands::SMB_COM_SESSION_SETUP_ANDX && header.uid == 0)
              response = SMB1::Packet::EmptyPacket.new
    Severity: Minor
    Found in lib/ruby_smb/server/server_client.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 do_read_smb2 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

                  def do_read_smb2(request)
                    handle = @handles[request.file_id.to_binary_s]
                    if handle.nil?
                      response = RubySMB::SMB2::Packet::ErrorPacket.new
                      response.smb2_header.nt_status = WindowsError::NTStatus::STATUS_FILE_CLOSED
    Severity: Minor
    Found in lib/ruby_smb/server/share/provider/disk/processor/read.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

    Severity
    Category
    Status
    Source
    Language