Skip to content

Commit a677749

Browse files
committed
Add specs for #read_asciiz and fix bugs there
1 parent f804d42 commit a677749

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/rex/image_source/image_source.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ def read_asciiz(offset)
2929
# FIXME, make me better
3030
string = ''
3131
loop do
32-
char = read(offset, 1)
33-
break if char == "\x00"
32+
begin
33+
char = read(offset, 1)
34+
rescue RangeError
35+
break
36+
end
37+
break if char.nil? || char == "\x00"
3438
offset += 1
3539
string << char
3640
end

spec/lib/rex/image_source/disk_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
described_class.new(file)
1818
end
1919

20+
it_should_behave_like 'Rex::ImageSource::ImageSource'
21+
2022
describe "#initialize" do
2123
subject(:disk_class) do
2224
described_class.allocate

spec/lib/rex/image_source/memory_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
described_class.new(raw_data)
1212
end
1313

14+
it_should_behave_like 'Rex::ImageSource::ImageSource'
15+
1416
describe "#initialize" do
1517
subject(:memory_class) do
1618
described_class.allocate

0 commit comments

Comments
 (0)