Skip to content

Commit 0c769e2

Browse files
committed
Fix constant leaks in Msf::Util::EXE spec
MSP-11130 Remove global $framework as it loads modules prior to suite run and they are not cleaned up.
1 parent 78ea930 commit 0c769e2

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

spec/lib/msf/util/exe_spec.rb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77
require 'support/shared/contexts/msf/util/exe'
88

99
describe Msf::Util::EXE do
10+
include_context 'Msf::Simple::Framework#modules loading'
1011

1112
subject do
1213
described_class
1314
end
1415

15-
$framework = Msf::Simple::Framework.create(
16-
:module_types => [ Msf::MODULE_NOP ],
17-
'DisableDatabase' => true
18-
)
19-
2016
describe '.win32_rwx_exec' do
2117
it "should contain the shellcode" do
2218
bin = subject.win32_rwx_exec("asdfjklASDFJKL")
@@ -32,7 +28,7 @@
3228

3329
describe '.to_executable_fmt' do
3430
it "should output nil when given a bogus format" do
35-
bin = subject.to_executable_fmt($framework, "", "", "", "does not exist", {})
31+
bin = subject.to_executable_fmt(framework, "", "", "", "does not exist", {})
3632

3733
bin.should == nil
3834
end
@@ -41,21 +37,34 @@
4137

4238
@platform_format_map.each do |plat, formats|
4339
context "with platform=#{plat}" do
40+
if plat == 'windows'
41+
before(:each) do
42+
load_and_create_module(
43+
module_type: 'encoder',
44+
reference_name: 'x86/shikata_ga_nai'
45+
)
46+
load_and_create_module(
47+
module_type: 'nop',
48+
reference_name: 'x86/opty2'
49+
)
50+
end
51+
end
52+
4453
let(:platform) do
4554
Msf::Module::PlatformList.transform(plat)
4655
end
4756

4857
it "should output nil when given bogus format" do
49-
bin = subject.to_executable_fmt($framework, formats.first[:arch], platform, "\xcc", "asdf", {})
58+
bin = subject.to_executable_fmt(framework, formats.first[:arch], platform, "\xcc", "asdf", {})
5059
bin.should == nil
5160
end
5261
it "should output nil when given bogus arch" do
53-
bin = subject.to_executable_fmt($framework, "asdf", platform, "\xcc", formats.first[:format], {})
62+
bin = subject.to_executable_fmt(framework, "asdf", platform, "\xcc", formats.first[:format], {})
5463
bin.should == nil
5564
end
5665
[ ARCH_X86, ARCH_X64, ARCH_X86_64, ARCH_PPC, ARCH_MIPSLE, ARCH_MIPSBE, ARCH_ARMLE ].each do |arch|
5766
it "returns nil when given bogus format for arch=#{arch}" do
58-
bin = subject.to_executable_fmt($framework, arch, platform, "\xcc", "asdf", {})
67+
bin = subject.to_executable_fmt(framework, arch, platform, "\xcc", "asdf", {})
5968
end
6069
end
6170

@@ -69,7 +78,7 @@
6978
end
7079

7180
it "returns an executable when given arch=#{arch}, fmt=#{fmt}" do
72-
bin = subject.to_executable_fmt($framework, arch, platform, "\xcc", fmt, {})
81+
bin = subject.to_executable_fmt(framework, arch, platform, "\xcc", fmt, {})
7382
bin.should be_a String
7483

7584
verify_bin_fingerprint(format_hash, bin)

0 commit comments

Comments
 (0)