rapid7/ruby_smb

View on GitHub

Showing 310 of 310 total issues

Method read has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

      def read(bytes: size, offset: 0)
        max_read = tree.client.server_max_read_size
        max_read = 65536 unless tree.client.server_supports_multi_credit
        atomic_read_size = [bytes, max_read].min
        credit_charge = 0
Severity: Minor
Found in lib/ruby_smb/smb2/file.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 transaction2_smb1_find_first2 has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

              def transaction2_smb1_find_first2(request)
                # see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-cifs/f93455dc-2bd7-4698-b91e-8c9c7abd63cf
                raise ArgumentError unless request.data_block.trans2_parameters.is_a? SMB1::Packet::Trans2::FindFirst2RequestTrans2Parameters

                subdir, _, search_pattern = request.data_block.trans2_parameters.filename.encode.gsub('\\', File::SEPARATOR).rpartition(File::SEPARATOR)
Severity: Major
Found in lib/ruby_smb/server/share/provider/disk/processor/query.rb - About 2 hrs to fix

    Method _open has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def _open(filename:, attributes: nil, options: nil, disposition: RubySMB::Dispositions::FILE_OPEN,
                        impersonation: RubySMB::ImpersonationLevels::SEC_IMPERSONATE, read: true, write: false, delete: false)
    
            create_request = RubySMB::SMB2::Packet::CreateRequest.new
            create_request = set_header_fields(create_request)
    Severity: Major
    Found in lib/ruby_smb/smb2/tree.rb - About 2 hrs to fix

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

        module Dcerpc
          # The Bind PDU as defined in
          # [The bind PDU](http://pubs.opengroup.org/onlinepubs/9629399/chap12.htm#tagcjh_17_06_04_03)
          class Bind < BinData::Record
            PTYPE = PTypes::BIND
      Severity: Major
      Found in lib/ruby_smb/dcerpc/bind.rb and 1 other location - About 2 hrs to fix
      lib/ruby_smb/dcerpc/alter_context.rb on lines 2..25

      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 77.

      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

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

        module Dcerpc
          # The Alter context PDU as defined in
          # [The alter_context PDU](https://pubs.opengroup.org/onlinepubs/9629399/chap12.htm#tagcjh_17_06_04_01)
          class AlterContext < BinData::Record
            PTYPE = PTypes::ALTER_CONTEXT
      Severity: Major
      Found in lib/ruby_smb/dcerpc/alter_context.rb and 1 other location - About 2 hrs to fix
      lib/ruby_smb/dcerpc/bind.rb on lines 2..25

      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 77.

      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

      Method handle_smb1 has 48 lines of code (exceeds 25 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 1 hr to fix

        Method ioctl_send_recv has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def ioctl_send_recv(action, options={})
                request = set_header_fields(RubySMB::SMB2::Packet::IoctlRequest.new(options))
                request.ctl_code = 0x0011C017
                request.flags.is_fsctl = 0x00000001
                # TODO: handle fragmentation when the request size > MAX_XMIT_FRAG
        Severity: Minor
        Found in lib/ruby_smb/smb2/pipe.rb - About 1 hr to fix

          Method read has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

                def read(bytes: @size, offset: 0)
                  atomic_read_size = [bytes, @tree.client.max_buffer_size].min
                  remaining_bytes = bytes
                  data = ''
          
          
          Severity: Minor
          Found in lib/ruby_smb/smb1/file.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 smb2_authenticate has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

                def smb2_authenticate
                  response = smb2_ntlmssp_negotiate
                  challenge_packet = smb2_ntlmssp_challenge_packet(response)
                  if @dialect == '0x0311'
                    update_preauth_hash(challenge_packet)
          Severity: Minor
          Found in lib/ruby_smb/client/authentication.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 _open has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

                def _open(filename:, flags: nil, options: nil, disposition: RubySMB::Dispositions::FILE_OPEN,
                          impersonation: RubySMB::ImpersonationLevels::SEC_IMPERSONATE, read: true, write: false, delete: false)
                  nt_create_andx_request = RubySMB::SMB1::Packet::NtCreateAndxRequest.new
                  nt_create_andx_request = set_header_fields(nt_create_andx_request)
          
          
          Severity: Minor
          Found in lib/ruby_smb/smb1/tree.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 15 (exceeds 5 allowed). Consider refactoring.
          Open

                def initialize(args = nil)
                  if args.nil?
                    super
                  elsif args.is_a? String
                    super(args)
          Severity: Minor
          Found in lib/ruby_smb/error.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

          Similar blocks of code found in 2 locations. 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: Major
          Found in lib/ruby_smb/dcerpc/winreg.rb and 1 other location - About 1 hr to fix
          lib/ruby_smb/dcerpc/winreg.rb on lines 376..396

          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 72.

          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

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

                def enum_registry_key(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: Major
          Found in lib/ruby_smb/dcerpc/winreg.rb and 1 other location - About 1 hr to fix
          lib/ruby_smb/dcerpc/winreg.rb on lines 403..423

          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 72.

          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

          Method drs_bind has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def drs_bind
                  drs_extensions_int = DrsExtensionsInt.new(
                    dw_flags: DRS_EXT_GETCHGREQ_V6 | DRS_EXT_GETCHGREPLY_V6 | DRS_EXT_GETCHGREQ_V8 | DRS_EXT_STRONG_ENCRYPTION,
                    dw_ext_caps: 0xFFFFFFFF
                  )
          Severity: Minor
          Found in lib/ruby_smb/dcerpc/drsr.rb - About 1 hr to fix

            Method fetch_alias_referent has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                def fetch_alias_referent(current: parent, ref: get_parameter(:ref_to), name: nil)
                  return if current.nil?
                  if current.get_parameter(:ref_to) == ref
                    raise ArgumentError.new(
                      "Pointer alias refering to #{ref} cannot be found. This referent "\
            Severity: Minor
            Found in lib/ruby_smb/dcerpc/ndr.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 do_num_bytes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                def do_num_bytes(struct_offset = 0, is_deferred: false)
                  sum = 0
                  if is_deferred
                    if is_a?(NdrStruct) && self.class.superclass.has_conformant_array
                      # align :max_count since it will be placed in front of the structure.
            Severity: Minor
            Found in lib/ruby_smb/dcerpc/ndr.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 negotiate has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                  def negotiate
                    request_packet  = negotiate_request
                    raw_response    = send_recv(request_packet)
                    response_packet = negotiate_response(raw_response)
                    # The list of dialect identifiers sent to the server is stored
            Severity: Minor
            Found in lib/ruby_smb/client/negotiation.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 extend_top_level_class has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                def extend_top_level_class
                  current = self
                  loop do
                    current.extend(TopLevelPlugin) unless current.is_a?(TopLevelPlugin)
                    if current.parent.nil?
            Severity: Minor
            Found in lib/ruby_smb/dcerpc/ndr.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 find has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                    def find(src, target, max_len)
                      result_offset = 0
                      result_length = 0
                      1.upto(max_len - 1) do |i|
                        offset = src.rindex(target[0...i])
            Severity: Minor
            Found in lib/ruby_smb/compression/lznt1.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 read has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def read(bytes: size, offset: 0)
                    max_read = tree.client.server_max_read_size
                    max_read = 65536 unless tree.client.server_supports_multi_credit
                    atomic_read_size = [bytes, max_read].min
                    credit_charge = 0
            Severity: Minor
            Found in lib/ruby_smb/smb2/file.rb - About 1 hr to fix
              Severity
              Category
              Status
              Source
              Language