diff --git a/lib/msf/core/data_store.rb b/lib/msf/core/data_store.rb index 72714fd742..6b39ce9c08 100644 --- a/lib/msf/core/data_store.rb +++ b/lib/msf/core/data_store.rb @@ -32,10 +32,10 @@ class DataStore < Hash # Figure out the deliminter, default to space. delim = /\s/ - if (option_str.index(',')) + if (option_str.split('=').length <= 2 or option_str.index(',') != nil) delim = ',' end - + # Split on the deliminter option_str.split(delim).each { |opt| var, val = opt.split('=') @@ -44,7 +44,8 @@ class DataStore < Hash if (var == nil or val == nil) var = "unknown" if (!var) - raise Rex::ArgumentParseError, "Invalid option specified: #{var}", caller + raise Rex::ArgumentParseError, "Invalid option specified: #{var}", + caller end # Store the value diff --git a/lib/msf/ui/console/shell.rb b/lib/msf/ui/console/shell.rb index b7afcf980a..89e6892d05 100644 --- a/lib/msf/ui/console/shell.rb +++ b/lib/msf/ui/console/shell.rb @@ -149,9 +149,15 @@ protected # Parse a line into an array of arguments # def parse_line(line) - line.gsub!("(\r|\n)", '') + line.gsub!(/(\r|\n)/, '') + + begin + return args = Rex::Parser::Arguments.from_s(line) + rescue ArgumentError + print_error("Parse error: #{$!}") + end - args = Rex::Parser::Arguments.from_s(line) + return [] end diff --git a/lib/rex/parser/arguments.rb b/lib/rex/parser/arguments.rb index c84d54d58c..0d80f89282 100644 --- a/lib/rex/parser/arguments.rb +++ b/lib/rex/parser/arguments.rb @@ -1,3 +1,5 @@ +require 'shellwords' + module Rex module Parser @@ -33,18 +35,7 @@ class Arguments # Takes a string and converts it into an array of arguments # def self.from_s(str) - # I am the king of sucking at regex. - sub = str.gsub(/["](.+?)[^\\]["]/) { |s| s.gsub(/\s/, '__SEP__') } - sub.gsub!(/[^\\](["])/) { |s| s[0..0] } - sub.gsub!(/(\\")/, '"') - - args = [] - - sub.split(/\s/).each { |arg| - args << arg.gsub(/__SEP__/, ' ') - } - - return args + Shellwords.shellwords(str) end #