Skip to content

Commit 3d624c0

Browse files
committed
Land rapid7#6719, datastore validation fix for file:
2 parents 72bde63 + e25525b commit 3d624c0

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

lib/msf/core/data_store.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ def []=(k, v)
2929

3030
opt = @options[k]
3131
unless opt.nil?
32-
unless opt.valid?(v)
33-
raise OptionValidateError.new(["Value '#{v}' is not valid for option '#{k}'#{['', ', try harder'].sample}"])
32+
if opt.validate_on_assignment?
33+
unless opt.valid?(v)
34+
raise OptionValidateError.new(["Value '#{v}' is not valid for option '#{k}'"])
35+
end
36+
v = opt.normalize(v)
3437
end
35-
v = opt.normalize(v)
3638
end
3739

3840
super(k,v)

lib/msf/core/opt_address_range.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def type
1212
return 'addressrange'
1313
end
1414

15+
def validate_on_assignment?
16+
false
17+
end
18+
1519
def normalize(value)
1620
return nil unless value.kind_of?(String)
1721
if (value =~ /^file:(.*)/)

lib/msf/core/opt_base.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ def type?(in_type)
7575
return (type == in_type)
7676
end
7777

78+
#
79+
# Returns true if this option can be validated on assignment
80+
#
81+
def validate_on_assignment?
82+
true
83+
end
84+
7885
#
7986
# If it's required and the value is nil or empty, then it's not valid.
8087
#

lib/msf/core/opt_path.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def type
1212
return 'path'
1313
end
1414

15+
def validate_on_assignment?
16+
false
17+
end
18+
1519
# Generally, 'value' should be a file that exists.
1620
def valid?(value)
1721
return false if empty_required_value?(value)

lib/msf/core/opt_raw.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def type
1212
return 'raw'
1313
end
1414

15+
def validate_on_assignment?
16+
false
17+
end
18+
1519
def normalize(value)
1620
if (value.to_s =~ /^file:(.*)/)
1721
path = $1

lib/msf/core/opt_string.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def type
1212
return 'string'
1313
end
1414

15+
def validate_on_assignment?
16+
false
17+
end
18+
1519
def normalize(value)
1620
if (value.to_s =~ /^file:(.*)/)
1721
path = $1

0 commit comments

Comments
 (0)