Skip to content

Commit d2fccf9

Browse files
author
jvazquez-r7
committed
Merge branch 'msftidy_badchars' of https://github.com/wchen-r7/metasploit-framework into wchen-r7-msftidy_badchars
2 parents 3e81fb2 + 86f41c4 commit d2fccf9

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

tools/msftidy.rb

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ def initialize(source_file)
3636

3737
##
3838
#
39-
# The following two functions only print what you throw at them.
40-
# With an option of displaying the line number.
39+
# The following two functions only print what you throw at them,
40+
# with the option of displying the line number. error() is meant
41+
# for mistakes that might actually break something.
4142
#
4243
##
4344

@@ -58,6 +59,70 @@ def error(txt, line=0)
5859
#
5960
##
6061

62+
def check_badchars
63+
badchars = %Q|&<=>|
64+
65+
in_super = false
66+
in_author = false
67+
68+
@source.each_line do |line|
69+
#
70+
# Mark our "super" code block
71+
#
72+
if !in_super and line =~ /[\n\t]+super\(/
73+
in_super = true
74+
elsif in_super and line =~ /[[:space:]]*def \w+[\(\w+\)]*/
75+
in_super = false
76+
break
77+
end
78+
79+
#
80+
# While in super() code block
81+
#
82+
if in_super and line =~ /'Name'[[:space:]]*=>[[:space:]]*['|"](.+)['|"]/
83+
# Now we're checking the module titlee
84+
mod_title = $1
85+
mod_title.each_char do |c|
86+
if badchars.include?(c)
87+
error("'#{c}' is a bad character in module title.")
88+
end
89+
end
90+
91+
if not mod_title.ascii_only?
92+
error("Please avoid unicode in module title.")
93+
end
94+
95+
# Since we're looking at the module title, this line clearly cannot be
96+
# the author block, so no point to run more code below.
97+
next
98+
end
99+
100+
#
101+
# Mark our 'Author' block
102+
#
103+
if in_super and !in_author and line =~ /'Author'[[:space:]]*=>/
104+
in_author = true
105+
elsif in_super and in_author and line =~ /\],*\n/
106+
in_author = false
107+
end
108+
109+
110+
#
111+
# While in 'Author' block, check for Twitter handles
112+
#
113+
if in_super and in_author and line =~ /['|"](.+)['|"]/
114+
author_name = $1
115+
if author_name =~ /^@.+$/
116+
error("No Twitter handle, please. Try leaving it in a comment instead.")
117+
end
118+
119+
if not author_name.ascii_only?
120+
error("Please avoid unicode in Author")
121+
end
122+
end
123+
end
124+
end
125+
61126
def check_extname
62127
if File.extname(@name) != '.rb'
63128
error("Module should be a '.rb' file, or it won't load.")
@@ -126,7 +191,7 @@ def check_title_format
126191
[words.first, words.last].each do |word|
127192
if word[0,1] =~ /[a-z]/ and word[1,1] !~ /[A-Z0-9]/
128193
next if word =~ /php[A-Z]/
129-
next if %w{iseemedia activePDF freeFTPd osCommerce myBB qdPM}.include? word
194+
next if %w{iseemedia activePDF freeFTPd osCommerce myBB qdPM inetd wallet.dat}.include? word
130195
warn("Improper capitalization in module title: '#{word}...'")
131196
end
132197
end
@@ -234,6 +299,7 @@ def load_file(file)
234299

235300
def run_checks(f_rel)
236301
tidy = Msftidy.new(f_rel)
302+
tidy.check_badchars
237303
tidy.check_extname
238304
tidy.test_old_rubies(f_rel)
239305
tidy.check_ranking

0 commit comments

Comments
 (0)