From 32db367ada81ce152edfb926c0c8a4cbfd6ff7c6 Mon Sep 17 00:00:00 2001 From: soh_cah_toa Date: Thu, 24 Apr 2014 23:28:11 -0400 Subject: [PATCH] Refactored ID filter checks into #is_valid_id?. Added call to #remove_rule! as well. --- extensions/dns/dns.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/extensions/dns/dns.rb b/extensions/dns/dns.rb index d1ed4d4d1..5bdf11202 100644 --- a/extensions/dns/dns.rb +++ b/extensions/dns/dns.rb @@ -63,11 +63,7 @@ module BeEF # @return [Hash] hash representation of rule (empty hash if rule wasn't found) def get_rule(id) @lock.synchronize do - if BeEF::Filters.hexs_only?(id) && - !BeEF::Filters.has_null?(id) && - !BeEF::Filters.has_non_printable_char?(id) && - id.length == 8 - + if is_valid_id?(id) rule = @database.get(id) rule.nil? ? {} : to_hash(rule) end @@ -81,8 +77,10 @@ module BeEF # @return [Boolean] true if rule was removed, otherwise false def remove_rule!(id) @lock.synchronize do - rule = @database.get(id) - rule.nil? ? false : rule.destroy + if is_valid_id?(id) + rule = @database.get(id) + rule.nil? ? false : rule.destroy + end end end @@ -160,6 +158,18 @@ module BeEF hash end + # Verifies that the given ID is valid. + # + # @param id [String] identifier to validate + # + # @return [Boolean] true if ID is valid, otherwise false + def is_valid_id?(id) + BeEF::Filters.hexs_only?(id) && + !BeEF::Filters.has_null?(id) && + !BeEF::Filters.has_non_printable_char?(id) && + id.length == 8 + end + # Helper method that formats the given resource class in a human-readable format. # # @param resource [Resolv::DNS::Resource::IN] resource class