Skip to content

Commit f2245ea

Browse files
author
jvazquez-r7
committed
Merge branch 'msftidy_fix' of https://github.com/wchen-r7/metasploit-framework into wchen-r7-msftidy_fix
2 parents 9909579 + acdce4c commit f2245ea

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tools/msftidy.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def red
2121
def yellow
2222
"\e[1;33;40m#{self}\e[0m"
2323
end
24+
25+
def ascii_only?
26+
self =~ Regexp.new('[\x00-\x08\x0b\x0c\x0e-\x19\x7f-\xff]', nil, 'n') ? false : true
27+
end
2428
end
2529

2630
class Msftidy
@@ -171,7 +175,7 @@ def check_badchars
171175
end
172176

173177
if not mod_title.ascii_only?
174-
error("Please avoid unicode in module title.")
178+
error("Please avoid unicode or non-printable characters in module title.")
175179
end
176180

177181
# Since we're looking at the module title, this line clearly cannot be
@@ -184,22 +188,27 @@ def check_badchars
184188
#
185189
if in_super and !in_author and line =~ /'Author'[[:space:]]*=>/
186190
in_author = true
187-
elsif in_super and in_author and line =~ /\],*\n/
191+
elsif in_super and in_author and line =~ /\],*\n/ or line =~ /['"][[:print:]]*['"][[:space:]]*=>/
188192
in_author = false
189193
end
190194

191195

192196
#
193197
# While in 'Author' block, check for Twitter handles
194198
#
195-
if in_super and in_author and line =~ /['|"](.+)['|"]/
196-
author_name = $1
199+
if in_super and in_author
200+
if line =~ /Author/
201+
author_name = line.scan(/\[[[:space:]]*['"](.+)['"]/).flatten[-1] || ''
202+
else
203+
author_name = line.scan(/['"](.+)['"]/).flatten[-1] || ''
204+
end
205+
197206
if author_name =~ /^@.+$/
198207
error("No Twitter handle, please. Try leaving it in a comment instead.")
199208
end
200209

201210
if not author_name.ascii_only?
202-
error("Please avoid unicode in Author")
211+
error("Please avoid unicode or non-printable characters in Author")
203212
end
204213
end
205214
end
@@ -246,7 +255,7 @@ def check_disclosure_date
246255
return if @source =~ /Generic Payload Handler/ or @source !~ / \< Msf::Exploit/
247256

248257
# Check disclosure date format
249-
if @source =~ /'DisclosureDate'.*\=\>[\x0d|\x20]*['|\"](.+)['|\"]/
258+
if @source =~ /'DisclosureDate'.*\=\>[\x0d\x20]*['\"](.+)['\"]/
250259
d = $1 #Captured date
251260
# Flag if overall format is wrong
252261
if d =~ /^... \d{1,2}\,* \d{4}/
@@ -267,7 +276,7 @@ def check_disclosure_date
267276
end
268277

269278
def check_title_casing
270-
if @source =~ /'Name'[[:space:]]*=>[[:space:]]*['|"](.+)['|"],*$/
279+
if @source =~ /'Name'[[:space:]]*=>[[:space:]]*['"](.+)['"],*$/
271280
words = $1.split
272281
words.each do |word|
273282
if %w{and or the for to in of as with a an}.include?(word)

0 commit comments

Comments
 (0)