Skip to content

Commit 6d72b5b

Browse files
committed
Land rapid7#6946 Fix a bug with OptPort validation when not req
2 parents c4aa99f + 53b989f commit 6d72b5b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/msf/core/opt_int.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ def type
1515
def normalize(value)
1616
if value.to_s.match(/^0x[a-fA-F\d]+$/)
1717
value.to_i(16)
18-
else
18+
elsif value.present?
1919
value.to_i
20+
else
21+
nil
2022
end
2123
end
2224

2325
def valid?(value, check_empty: true)
2426
return false if check_empty && empty_required_value?(value)
2527

26-
if value and not value.to_s.match(/^0x[0-9a-fA-F]+$|^-?\d+$/)
28+
if value.present? and not value.to_s.match(/^0x[0-9a-fA-F]+$|^-?\d+$/)
2729
return false
2830
end
2931

lib/msf/core/opt_port.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def type
1313
end
1414

1515
def valid?(value, check_empty: true)
16-
port = normalize(value)
16+
port = normalize(value).to_i
1717
super && port <= 65535 && port >= 0
1818
end
1919
end

0 commit comments

Comments
 (0)