From bf28203159adc6b6d8bf1bffacffc8d62ccf31b5 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Tue, 19 Oct 2010 22:51:37 +0000 Subject: [PATCH] Try to recover from binary in the XML import, report in the dlog if you run into trouble. git-svn-id: file:///home/svn/framework3/trunk@10756 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/db.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/msf/core/db.rb b/lib/msf/core/db.rb index fcfe2d879a..df733c72c9 100644 --- a/lib/msf/core/db.rb +++ b/lib/msf/core/db.rb @@ -1842,7 +1842,18 @@ class DBManager # Returns a REXML::Document from the given data. def rexmlify(data) - doc = data.kind_of?(REXML::Document) ? data : REXML::Document.new(data) + if data.kind_of?(REXML::Document) + return data + else + # Make an attempt to recover from a REXML import fail, since + # it's better than dying outright. + begin + return REXML::Document.new(data) + rescue REXML::ParseException => e + dlog("REXML error: Badly formatted XML, attempting to recover. Error was: #{e.inspect}") + return REXML::Document.new(data.gsub(/([\x00-\x08\x0b\x0c\x0e-\x19\x80-\xff])/){ |x| "\\x%.2x" % x.unpack("C*")[0] }) + end + end end # Handles timestamps from Metasploit Express imports.