From a677749f5b3e9fdf3d3ff3d29f2a8e0c62fc8565 Mon Sep 17 00:00:00 2001 From: jvazquez-r7 Date: Mon, 22 Sep 2014 12:14:21 -0500 Subject: [PATCH] Add specs for #read_asciiz and fix bugs there --- lib/rex/image_source/image_source.rb | 8 ++++++-- spec/lib/rex/image_source/disk_spec.rb | 2 ++ spec/lib/rex/image_source/memory_spec.rb | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/rex/image_source/image_source.rb b/lib/rex/image_source/image_source.rb index 302c8dd430..33c7e49138 100644 --- a/lib/rex/image_source/image_source.rb +++ b/lib/rex/image_source/image_source.rb @@ -29,8 +29,12 @@ class ImageSource # FIXME, make me better string = '' loop do - char = read(offset, 1) - break if char == "\x00" + begin + char = read(offset, 1) + rescue RangeError + break + end + break if char.nil? || char == "\x00" offset += 1 string << char end diff --git a/spec/lib/rex/image_source/disk_spec.rb b/spec/lib/rex/image_source/disk_spec.rb index d676482209..ce997705ca 100644 --- a/spec/lib/rex/image_source/disk_spec.rb +++ b/spec/lib/rex/image_source/disk_spec.rb @@ -17,6 +17,8 @@ describe Rex::ImageSource::Disk do described_class.new(file) end + it_should_behave_like 'Rex::ImageSource::ImageSource' + describe "#initialize" do subject(:disk_class) do described_class.allocate diff --git a/spec/lib/rex/image_source/memory_spec.rb b/spec/lib/rex/image_source/memory_spec.rb index 6761b5eee9..d2246ac83c 100644 --- a/spec/lib/rex/image_source/memory_spec.rb +++ b/spec/lib/rex/image_source/memory_spec.rb @@ -11,6 +11,8 @@ describe Rex::ImageSource::Memory do described_class.new(raw_data) end + it_should_behave_like 'Rex::ImageSource::ImageSource' + describe "#initialize" do subject(:memory_class) do described_class.allocate