Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rex/proto/dns/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ def default_dispatch_request(cli,data)
# Finalize answers in response
# Check for empty response prior to sending
if req.answer.size < 1
req.header.rCode = Dnsruby::RCode::NOERROR
req.header.rcode = Dnsruby::RCode::NOERROR
end
req.header.qr = true # Set response bit
send_response(cli, req.data)
send_response(cli, req.encode)
end

#
Expand Down
40 changes: 40 additions & 0 deletions spec/lib/rex/proto/dns/server_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'rex/proto/dns'

RSpec.describe Rex::Proto::DNS::Server do
subject(:server) { described_class.new }

let(:cli) { double('client', write: nil) }

# a real, encodable query for a name that is in neither the cache nor
# anything the stubbed resolver knows about
def query_for(name)
query = Dnsruby::Message.new
query.add_question(Dnsruby::Name.create("#{name}."), Dnsruby::Types::A)
query.encode
end

describe '#default_dispatch_request' do
context 'when the forwarded response carries no answers' do
before do
# the resolver forwards the query and comes back empty, which is the
# path that finalizes an empty response - the one that crashed
empty_response = Dnsruby::Message.new
server.fwd_res = double('resolver', send: empty_response)
end

it 'does not raise' do
expect { server.default_dispatch_request(cli, query_for('empty.example.com')) }.not_to raise_error
end

it 'sends a well formed, encoded response back to the client' do
expect(cli).to receive(:write) do |data|
expect(data).to be_a(String)
reply = Dnsruby::Message.decode(data)
expect(reply.header.get_header_rcode).to eq(Dnsruby::RCode::NOERROR)
expect(reply.header.qr).to eq(true)
end
server.default_dispatch_request(cli, query_for('empty.example.com'))
end
end
end
end
Loading