Commit a1caa93a authored by JINMEI Tatuya's avatar JINMEI Tatuya

changed the types of QueryTask::qclass/qtype/section from reference to real

object so that they'll be valid regardless of how the QueryTask is constructed.

In the current usage patter the previous behavior is probably safe, but
since this object is passed beyond a scope of a single function, there's
always a risk of retaining a stale reference to a temporary object.  This fix
solves that potential problem.

Note that copy of these member objects should be cheap because in this sense
they are mostly native integer types.


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1395 e5f2f494-b856-4b98-b285-d166d9295462
parent a8e0d0f2
......@@ -418,14 +418,14 @@ tryWildcard(Query& q, QueryTaskPtr task, const DataSrc* ds,
return (DataSrc::SUCCESS);
}
int nlen = task->qname.getLabelCount();
int diff = nlen - zonename->getLabelCount();
const int nlen = task->qname.getLabelCount();
const int diff = nlen - zonename->getLabelCount();
if (diff < 1) {
return (DataSrc::SUCCESS);
}
RRsetList wild;
Name star("*");
const Name star("*");
uint32_t rflags = 0;
for (int i = 1; i <= diff; ++i) {
......
......@@ -19,18 +19,15 @@
#include <boost/shared_ptr.hpp>
#include <dns/name.h>
#include <dns/message.h>
#include <dns/rrtype.h>
#include <dns/rrclass.h>
#include <queue>
namespace isc {
namespace dns {
class Name;
class Message;
class Section;
class RRClass;
class RRType;
}
namespace auth {
// An individual task to be carried out by the query logic
......@@ -47,12 +44,12 @@ public:
// The standard query tuple: qname/qclass/qtype.
// Note that qtype is ignored in the GLUE_QUERY/NOGLUE_QUERY case.
const isc::dns::Name qname;
const isc::dns::RRClass& qclass;
const isc::dns::RRType& qtype;
const isc::dns::RRClass qclass;
const isc::dns::RRType qtype;
// The section of the reply into which the data should be
// written after it has been fetched from the data source.
const isc::dns::Section& section;
const isc::dns::Section section;
// The op field indicates the operation to be carried out by
// this query task:
......
......@@ -10,6 +10,7 @@ run_unittests_SOURCES += unittest_util.h unittest_util.cc
run_unittests_SOURCES += datasrc_unittest.cc
run_unittests_SOURCES += sqlite3_unittest.cc
run_unittests_SOURCES += static_unittest.cc
run_unittests_SOURCES += query_unittest.cc
run_unittests_SOURCES += test_datasrc.h test_datasrc.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
......
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
#include <gtest/gtest.h>
#include <dns/name.h>
#include <dns/rrtype.h>
#include <dns/rrclass.h>
#include <auth/query.h>
namespace {
using namespace isc::dns;
using namespace isc::auth;
class QueryTest : public ::testing::Test {
protected:
QueryTest() :
name(Name("www.example.com")),
rrtype(RRType::A()),
rrclass(RRClass::IN())
{}
const Name name;
const RRType rrtype;
const RRClass rrclass;
};
QueryTaskPtr
createTask(const Name& name, const RRClass& rrclass0, const RRType& rrtype0) {
RRType rrtype(rrtype0);
return (QueryTaskPtr(new QueryTask(name, rrclass0, rrtype,
QueryTask::SIMPLE_QUERY)));
}
// Check the QueryTask created using a temporary RRType object will remain
// valid.
TEST_F(QueryTest, constructWithTemporary) {
QueryTaskPtr task_a = createTask(name, rrclass, RRType::A());
QueryTaskPtr task_aaaa = createTask(name, rrclass, RRType::AAAA());
EXPECT_EQ(rrtype, task_a->qtype);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment