1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-10-16 01:21:15 +02:00

Enforce binary encoding on non-modules, no encoding on modules

This commit is contained in:
Jon Hart 2014-07-21 14:22:15 -07:00
parent 6185721a61
commit bfa89bb3a5
6 changed files with 30 additions and 4 deletions

View File

@ -39,6 +39,11 @@ Style/MethodLength:
often exceed 200 lines.
Max: 300
# Basically everything in metasploit needs binary encoding, not UTF-8.
# Disable this here and enforce it through msftidy
Style/Encoding:
Enabled: false
Style/NumericLiterals:
Enabled: false
Description: 'This often hurts readability for exploit-ish code.'

View File

@ -1,4 +1,4 @@
# -*- coding: binary -*-
# encoding: binary
# SIP protocol support
require 'rex/proto/sip/response'

View File

@ -1,4 +1,4 @@
# -*- coding: binary -*-
# encoding: binary
module Rex
module Proto

View File

@ -1,4 +1,3 @@
# -*- coding: binary -*-
##
# This module requires Metasploit: http//metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework

View File

@ -1,4 +1,3 @@
# -*- coding: binary -*-
##
# This module requires Metasploit: http//metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework

View File

@ -12,6 +12,7 @@ require 'time'
CHECK_OLD_RUBIES = !!ENV['MSF_CHECK_OLD_RUBIES']
SUPPRESS_INFO_MESSAGES = !!ENV['MSF_SUPPRESS_INFO_MESSAGES']
ENCODING_REGEX = /^# (?:\-\*\- )?encoding:\s*(\S+)/
if CHECK_OLD_RUBIES
require 'rvm'
@ -109,6 +110,27 @@ class Msftidy
end
end
# Check that modules don't have any encoding comment and that
# non-modules have an explicity binary encoding comment
def check_encoding
# coding/encoding lines must be the first or second line if present
encoding_lines = @source.lines.to_a[0,2].select { |l| l =~ ENCODING_REGEX }
if @full_filepath =~ /(?:^|\/)modules\//
warn('Modules do not need an encoding comment') unless encoding_lines.empty?
else
if encoding_lines.empty?
warn('Non-modules must have an encoding comment')
else
encoding_line = encoding_lines.first
encoding_line =~ ENCODING_REGEX
encoding_type = Regexp.last_match(1)
unless encoding_type == 'binary'
warn("Non-modules must have a binary encoding comment, not #{encoding_type}")
end
end
end
end
def check_shebang
if @source.lines.first =~ /^#!/
warn("Module should not have a #! line")
@ -583,6 +605,7 @@ def run_checks(full_filepath)
tidy = Msftidy.new(full_filepath)
tidy.check_mode
tidy.check_shebang
tidy.check_encoding
tidy.check_nokogiri
tidy.check_rubygems
tidy.check_ref_identifiers