<commit_before>module Codesake
  module Dawn
    module Kb
      module RubyVersionCheck
        include BasicCheck
        
        # Array of hashes in the {:engine=>"ruby", :version=>"1.9.3", :patchlevel=>"p342"} form
        attr_accessor   :safe_rubies
        # Hash in the {:engine=>"ruby", :version=>"1.9.3", :patchlevel=>"p342"} form
        attr_accessor   :detected_ruby

        def vuln?
          vv_a = []
          vv_p = []
          vv_e = []
          vp = false


          @safe_rubies.each do |ss|
            vv_e << ss[:engine]
            vv_a << ss[:version]
            vv_p << ss[:patchlevel].split("p")[1].to_i
          end

          vengine = self.is_vulnerable_engine?(detected_ruby[:engine], vv_e)
          vv = self.is_vulnerable_version?(detected_ruby[:version], vv_a)
          ve = false

          ve = self.is_same_version?(detected_ruby[:version], vv_a) 
          vp = is_vulnerable_patchlevel?(detected_ruby[:version], detected_ruby[:patchlevel])

          debug_me("D:#{self.name}, VENGINE=#{vengine}, VV=#{vv}, VE=#{ve}, VP=#{vp}->#{vv && vengine}, #{(ve && vp && vengine )}")
          debug_me("S:#{@safe_rubies}")
          debug_me("DD:#{@detected_ruby}")



          if ( vv && vengine)
            @status = vp if ve
            @status = true unless ve
          else
            @status = (ve && vp && vengine )
          end

          debug_me("STATUS:#{@status}")
          self.evidences << "#{@detected_ruby[:engine]} v#{@detected_ruby[:version]}-#{@detected_ruby[:patchlevel]} detected" if @status
          
          return @status

          # return true if ( vv && vengine )
          # return (ve && vp && vengine )
        end
        
        def is_vulnerable_engine?(target, fixes = [])
          fixes.each do |f|
            return true if f == target
          end
          false
        end

        def is_same_version?(target, fixes = [])
          fixes.each do |f|<commit_msg>Initial VersionCheck usage for Ruby interpreter version check<commit_after>module Codesake
  module Dawn
    module Kb
      module RubyVersionCheck
        include BasicCheck
        # Array of hashes in the {:engine=>"ruby", :version=>"1.9.3", :patchlevel=>"p342"} form
        attr_accessor   :safe_rubies
        # Hash in the {:engine=>"ruby", :version=>"1.9.3", :patchlevel=>"p342"} form
        attr_accessor   :detected_ruby

        def vuln?
          vv_a = []
          vv_p = []
          vv_e = []
          vp = false


          @safe_rubies.each do |ss|
            vv_e << ss[:engine]
            vv_a << ss[:version]
            vv_p << ss[:patchlevel].split("p")[1].to_i
          end

          version_check = Codesake::Dawn::Kb::VersionCheck.new(:safe=>vv_a,:detected=>detected_ruby[:version])

          vengine = self.is_vulnerable_engine?(detected_ruby[:engine], vv_e)
          # vv = version_check.is_vulnerable_version?(detected_ruby[:version], vv_a)
          vv = version_check.vuln?
          ve = false

          ve = self.is_same_version?(detected_ruby[:version], vv_a)
          vp = is_vulnerable_patchlevel?(detected_ruby[:version], detected_ruby[:patchlevel])

          debug_me("D:#{self.name}, VENGINE=#{vengine}, VV=#{vv}, VE=#{ve}, VP=#{vp}->#{vv && vengine}, #{(ve && vp && vengine )}")
          debug_me("S:#{@safe_rubies}")
          debug_me("DD:#{@detected_ruby}")



          if ( vv && vengine)
            @status = vp if ve
            @status = true unless ve
          else
            @status = (ve && vp && vengine )
          end

          debug_me("STATUS:#{@status}")
          self.evidences << "#{@detected_ruby[:engine]} v#{@detected_ruby[:version]}-#{@detected_ruby[:patchlevel]} detected" if @status
          return @status

          # return true if ( vv && vengine )
          # return (ve && vp && vengine )
        end
        def is_vulnerable_engine?(target, fixes = [])
          fixes.each do |f|
            return true if f == target
          end
          false
        end

        def is_same_version?(target, fixes = [])
          fixes.each do |f|
{'fraction_non_alphanumeric': 0.14180929095354522, 'fraction_numerical': 0.006356968215158924, 'mean_word_length': 2.0438988095238093, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2638775', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1319, 'n_words': 266}