rapid7/ruby_smb

View on GitHub
lib/ruby_smb/server/server_client.rb

Summary

Maintainability
F
3 days
Test Coverage

Method handle_smb has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

      def handle_smb(raw_request)
        response = nil

        case raw_request[0...4].unpack1('L>')
        when RubySMB::SMB1::SMB_PROTOCOL_ID
Severity: Minor
Found in lib/ruby_smb/server/server_client.rb - About 6 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

File server_client.rb has 362 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module RubySMB
  class Server
    # This class represents a single connected client to the server. It stores and processes connection specific related
    # information.
    class ServerClient
Severity: Minor
Found in lib/ruby_smb/server/server_client.rb - About 4 hrs to fix

    Method _handle_smb2 has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

          def _handle_smb2(raw_request)
            begin
              header = RubySMB::SMB2::SMB2Header.read(raw_request)
            rescue IOError => e
              logger.error("Caught a #{e.class} while reading the SMB2 header (#{e.message})")
    Severity: Minor
    Found in lib/ruby_smb/server/server_client.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 handle_smb2 has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def handle_smb2(raw_request, header)
            session_required = !(header.command == SMB2::Commands::SESSION_SETUP && header.session_id == 0)
    
            if header.flags.related_operations == 0
              @smb2_related_operations_state.clear
    Severity: Major
    Found in lib/ruby_smb/server/server_client.rb - About 2 hrs to fix

      Method handle_smb has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def handle_smb(raw_request)
              response = nil
      
              case raw_request[0...4].unpack1('L>')
              when RubySMB::SMB1::SMB_PROTOCOL_ID
      Severity: Major
      Found in lib/ruby_smb/server/server_client.rb - About 2 hrs to fix

        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 run has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

                def run
                  loop do
                    begin
                      raw_request = recv_packet
                    rescue RubySMB::Error::CommunicationError
          Severity: Minor
          Found in lib/ruby_smb/server/server_client.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 handle_smb2 has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                def handle_smb2(raw_request, header)
                  session_required = !(header.command == SMB2::Commands::SESSION_SETUP && header.session_id == 0)
          
                  if header.flags.related_operations == 0
                    @smb2_related_operations_state.clear
          Severity: Minor
          Found in lib/ruby_smb/server/server_client.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 _handle_smb2 has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def _handle_smb2(raw_request)
                  begin
                    header = RubySMB::SMB2::SMB2Header.read(raw_request)
                  rescue IOError => e
                    logger.error("Caught a #{e.class} while reading the SMB2 header (#{e.message})")
          Severity: Minor
          Found in lib/ruby_smb/server/server_client.rb - About 1 hr to fix

            Method send_packet has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                  def send_packet(packet)
                    case metadialect&.family
                    when Dialect::FAMILY_SMB1
                      session_id = packet.smb_header.uid
                    when Dialect::FAMILY_SMB2
            Severity: Minor
            Found in lib/ruby_smb/server/server_client.rb - About 55 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

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

                      if response.is_a?(SMB2::Packet::ErrorPacket)
                        response.smb2_header.command = header.command if response.smb2_header.command == 0
                        response.smb2_header.flags.reply = 1
                        nt_status = response.smb2_header.nt_status.to_i
                        message = "Sending an error packet for SMB2 command: #{SMB2::Commands.name(header.command)}, status: 0x#{nt_status.to_s(16).rjust(8, '0')}"
            Severity: Major
            Found in lib/ruby_smb/server/server_client.rb and 1 other location - About 1 hr to fix
            lib/ruby_smb/server/server_client.rb on lines 101..109

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

            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

                        if response.is_a?(SMB1::Packet::EmptyPacket)
                          response.smb_header.command = header.command if response.smb_header.command == 0
                          response.smb_header.flags.reply = 1
                          nt_status = response.smb_header.nt_status.to_i
                          message = "Sending an error packet for SMB1 command: #{SMB1::Commands.name(header.command)}, status: 0x#{nt_status.to_s(16).rjust(8, '0')}"
            Severity: Major
            Found in lib/ruby_smb/server/server_client.rb and 1 other location - About 1 hr to fix
            lib/ruby_smb/server/server_client.rb on lines 433..441

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

            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

                      begin
                        header = RubySMB::SMB1::SMBHeader.read(raw_request)
                      rescue IOError => e
                        logger.error("Caught a #{e.class} while reading the SMB1 header (#{e.message})")
                        disconnect!
            Severity: Minor
            Found in lib/ruby_smb/server/server_client.rb and 1 other location - About 15 mins to fix
            lib/ruby_smb/server/server_client.rb on lines 415..421

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

            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

                    begin
                      header = RubySMB::SMB2::SMB2Header.read(raw_request)
                    rescue IOError => e
                      logger.error("Caught a #{e.class} while reading the SMB2 header (#{e.message})")
                      disconnect!
            Severity: Minor
            Found in lib/ruby_smb/server/server_client.rb and 1 other location - About 15 mins to fix
            lib/ruby_smb/server/server_client.rb on lines 81..87

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

            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