Skip to content

Commit bb6201d

Browse files
committed
Fixing nil bug and making format constant
The date format has been moved into a constant variable. Certain modules do not have a disclosure_date. For example, ‘checkvm’. This necessitated checking disclosure_date for nil before attempting a format conversion. Also, there was an additional location in core.rb that needed the formatting / nil check added. Specs were also updated appropriately.
1 parent f0a8f40 commit bb6201d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class Core
9797
# mode.
9898
DefangedProhibitedDataStoreElements = [ "MsfModulePaths" ]
9999

100+
# Constant for disclosure date formatting in search functions
101+
DISCLOSURE_DATE_FORMAT = "%Y-%m-%d"
100102
# Returns the list of commands supported by this command dispatcher
101103
def commands
102104
{
@@ -1488,7 +1490,7 @@ def cmd_search(*args)
14881490
next if not o
14891491

14901492
if not o.search_filter(match)
1491-
tbl << [ o.fullname, o.disclosure_date.strftime("%Y-%m-%d"), o.rank_to_s, o.name ]
1493+
tbl << [ o.fullname, o.disclosure_date.nil? ? "" : o.disclosure_date.strftime(DISCLOSURE_DATE_FORMAT), o.rank_to_s, o.name ]
14921494
end
14931495
end
14941496
end
@@ -1503,7 +1505,7 @@ def cmd_search(*args)
15031505
def search_modules_sql(search_string)
15041506
tbl = generate_module_table("Matching Modules")
15051507
framework.db.search_modules(search_string).each do |o|
1506-
tbl << [ o.fullname, o.disclosure_date.strftime("%Y-%m-%d"), RankingName[o.rank].to_s, o.name ]
1508+
tbl << [ o.fullname, o.disclosure_date.nil? ? "" : o.disclosure_date.strftime(DISCLOSURE_DATE_FORMAT), RankingName[o.rank].to_s, o.name ]
15071509
end
15081510
print_line(tbl.to_s)
15091511
end
@@ -3239,7 +3241,7 @@ def show_module_set(type, module_set, regex = nil, minrank = nil, opts = nil) #
32393241
end
32403242
end
32413243
if (opts == nil or show == true)
3242-
tbl << [ refname, o.disclosure_date||"", o.rank_to_s, o.name ]
3244+
tbl << [ refname, o.disclosure_date.nil? ? "" : o.disclosure_date.strftime(DISCLOSURE_DATE_FORMAT), o.rank_to_s, o.name ]
32433245
end
32443246
end
32453247
end

spec/lib/msf/ui/command_dispatcher/core_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def cell(table, row, column)
8282
end
8383

8484
it 'should have disclosure date in second column' do
85-
cell(printed_table, 0, 1).should include(module_detail.disclosure_date.to_s)
85+
cell(printed_table, 0, 1).should include(module_detail.disclosure_date.strftime("%Y-%m-%d"))
8686
end
8787

8888
it 'should have rank name in third column' do

0 commit comments

Comments
 (0)