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.bug/bundler_fix
parent
72bde63397
commit
e25525b4a7
|
@ -29,10 +29,12 @@ class DataStore < Hash
|
|||
|
||||
opt = @options[k]
|
||||
unless opt.nil?
|
||||
unless opt.valid?(v)
|
||||
raise OptionValidateError.new(["Value '#{v}' is not valid for option '#{k}'#{['', ', try harder'].sample}"])
|
||||
if opt.validate_on_assignment?
|
||||
unless opt.valid?(v)
|
||||
raise OptionValidateError.new(["Value '#{v}' is not valid for option '#{k}'"])
|
||||
end
|
||||
v = opt.normalize(v)
|
||||
end
|
||||
v = opt.normalize(v)
|
||||
end
|
||||
|
||||
super(k,v)
|
||||
|
|
|
@ -12,6 +12,10 @@ class OptAddressRange < OptBase
|
|||
return 'addressrange'
|
||||
end
|
||||
|
||||
def validate_on_assignment?
|
||||
false
|
||||
end
|
||||
|
||||
def normalize(value)
|
||||
return nil unless value.kind_of?(String)
|
||||
if (value =~ /^file:(.*)/)
|
||||
|
|
|
@ -75,6 +75,13 @@ module Msf
|
|||
return (type == in_type)
|
||||
end
|
||||
|
||||
#
|
||||
# Returns true if this option can be validated on assignment
|
||||
#
|
||||
def validate_on_assignment?
|
||||
true
|
||||
end
|
||||
|
||||
#
|
||||
# If it's required and the value is nil or empty, then it's not valid.
|
||||
#
|
||||
|
|
|
@ -12,6 +12,10 @@ class OptPath < OptBase
|
|||
return 'path'
|
||||
end
|
||||
|
||||
def validate_on_assignment?
|
||||
false
|
||||
end
|
||||
|
||||
# Generally, 'value' should be a file that exists.
|
||||
def valid?(value)
|
||||
return false if empty_required_value?(value)
|
||||
|
|
|
@ -12,6 +12,10 @@ class OptRaw < OptBase
|
|||
return 'raw'
|
||||
end
|
||||
|
||||
def validate_on_assignment?
|
||||
false
|
||||
end
|
||||
|
||||
def normalize(value)
|
||||
if (value.to_s =~ /^file:(.*)/)
|
||||
path = $1
|
||||
|
|
|
@ -12,6 +12,10 @@ class OptString < OptBase
|
|||
return 'string'
|
||||
end
|
||||
|
||||
def validate_on_assignment?
|
||||
false
|
||||
end
|
||||
|
||||
def normalize(value)
|
||||
if (value.to_s =~ /^file:(.*)/)
|
||||
path = $1
|
||||
|
|
Loading…
Reference in New Issue