From e5186edd13c681301893d2894f1dcfd1a80dc9aa Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Wed, 13 Jul 2005 22:57:29 +0000 Subject: [PATCH] option import fix, switched to using shellwords git-svn-id: file:///home/svn/incoming/trunk@2748 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/data_store.rb | 7 ++++--- lib/msf/ui/console/shell.rb | 10 ++++++++-- lib/rex/parser/arguments.rb | 15 +++------------ 3 files changed, 15 insertions(+), 17 deletions(-) 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 #