Commit 69dfb454 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[master] Merge branch 'trac2887'

parents c66811b7 3b1551b2
......@@ -28,7 +28,6 @@
#include <stdint.h>
#include <algorithm>
#include <cstring>
#include <typeinfo> // for bad_cast
#include <new> // for the placement new
using namespace isc::dns;
......@@ -41,13 +40,12 @@ namespace memory {
namespace {
RRType
getCoveredType(const Rdata& rdata) {
try {
const generic::RRSIG& rrsig_rdata =
dynamic_cast<const generic::RRSIG&>(rdata);
return (rrsig_rdata.typeCovered());
} catch (const std::bad_cast&) {
const generic::RRSIG* rrsig_rdata =
dynamic_cast<const generic::RRSIG*>(&rdata);
if (!rrsig_rdata) {
isc_throw(BadValue, "Non RRSIG is given where it's expected");
}
return (rrsig_rdata->typeCovered());
}
// A helper for lowestTTL: restore RRTTL object from wire-format 32-bit data.
......
......@@ -293,8 +293,16 @@ RRset_addRdata(PyObject* self, PyObject* args) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"Rdata type to add must match type of RRset");
return (NULL);
} catch (const exception& ex) {
const string ex_what =
"Unexpected failure adding rrset Rdata: " +
string(ex.what());
PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
PyErr_SetString(PyExc_SystemError,
"Unexpected failure adding rrset Rdata");
}
return (NULL);
}
PyObject*
......
......@@ -78,7 +78,12 @@ class TestModuleSpec(unittest.TestCase):
def test_add_rdata(self):
# no iterator to read out yet (TODO: add addition test once implemented)
self.assertRaises(TypeError, self.rrset_a.add_rdata,
# This should result in TypeError, but FreeBSD 9.1 cannot correctly
# catch the expected internal C++ exception, resulting in SystemError.
# In general it's not a good practice to weaken the test condition for
# a limited set of buggy environment, but this seems to be the only
# case it could fail this way, so we'd live with it. See #2887.
self.assertRaises((TypeError, SystemError), self.rrset_a.add_rdata,
Rdata(RRType("NS"), RRClass("IN"), "test.name."))
def test_to_text(self):
......
......@@ -59,13 +59,14 @@ namespace {
// of the constructor below.
const any::TSIG&
castToTSIGRdata(const rdata::Rdata& rdata) {
try {
return (dynamic_cast<const any::TSIG&>(rdata));
} catch (std::bad_cast&) {
const any::TSIG* tsig_rdata =
dynamic_cast<const any::TSIG*>(&rdata);
if (!tsig_rdata) {
isc_throw(DNSMessageFORMERR,
"TSIG record is being constructed from "
"incompatible RDATA:" << rdata.toText());
}
return (*tsig_rdata);
}
}
......
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