Skip to content

Commit e25525b

Browse files
author
Brent Cook
committed
avoid validating file-based datastore options on assignment
file:/ strings are special with some datastore options, causing them to read a file rather than emitting the exact string. This causes a couple of problems. 1. the valid? check needs to be special on assignment, since normalization really means normalizing the path, not playing with the value as we would do for other types 2. there are races or simply out-of-order assignments when running commands like 'services -p 80 -R', where the datastore option is assigned before the file is actually written. This is the 'easy' fix of disabling assignment validation (which we didn't have before anyway) for types that can expect a file:/ prefix.
1 parent 72bde63 commit e25525b

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)