[svn] commit: r1350 - in /trunk/src/lib/dns: message.cc message.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Mar 12 05:04:37 UTC 2010
Author: jinmei
Date: Fri Mar 12 05:04:36 2010
New Revision: 1350
Log:
introduced Message::parseHeader() so that we can perform minimal level
sanity check on incoming messages first. Message::fromWire() internall
calls parseHeader().
Modified:
trunk/src/lib/dns/message.cc
trunk/src/lib/dns/message.h
Modified: trunk/src/lib/dns/message.cc
==============================================================================
--- trunk/src/lib/dns/message.cc (original)
+++ trunk/src/lib/dns/message.cc Fri Mar 12 05:04:36 2010
@@ -201,6 +201,7 @@
flags_t flags_;
bool dnssec_ok_;
+ bool header_parsed_;
static const unsigned int SECTION_MAX = 4; // TODO: revisit this design
int counts_[SECTION_MAX]; // TODO: revisit this definition
vector<QuestionPtr> questions_;
@@ -243,6 +244,7 @@
counts_[i] = 0;
}
+ header_parsed_ = false;
questions_.clear();
rrsets_[sectionCodeToId(Section::ANSWER())].clear();
rrsets_[sectionCodeToId(Section::AUTHORITY())].clear();
@@ -524,10 +526,15 @@
}
void
-Message::fromWire(InputBuffer& buffer)
-{
+Message::parseHeader(InputBuffer& buffer) {
+ if (impl_->mode_ != Message::PARSE) {
+ isc_throw(InvalidMessageOperation,
+ "Message parse attempted in non parse mode");
+ }
+
if ((buffer.getLength() - buffer.getPosition()) < HEADERLEN) {
- isc_throw(MessageTooShort, "");
+ isc_throw(MessageTooShort, "Malformed DNS message (short length): "
+ << buffer.getLength() - buffer.getPosition());
}
impl_->qid_ = buffer.readUint16();
@@ -539,6 +546,20 @@
impl_->counts_[Section::ANSWER().getCode()] = buffer.readUint16();
impl_->counts_[Section::AUTHORITY().getCode()] = buffer.readUint16();
impl_->counts_[Section::ADDITIONAL().getCode()] = buffer.readUint16();
+
+ impl_->header_parsed_ = true;
+}
+
+void
+Message::fromWire(InputBuffer& buffer) {
+ if (impl_->mode_ != Message::PARSE) {
+ isc_throw(InvalidMessageOperation,
+ "Message parse attempted in non parse mode");
+ }
+
+ if (!impl_->header_parsed_) {
+ parseHeader(buffer);
+ }
impl_->counts_[Section::QUESTION().getCode()] =
impl_->parseQuestion(buffer);
Modified: trunk/src/lib/dns/message.h
==============================================================================
--- trunk/src/lib/dns/message.h (original)
+++ trunk/src/lib/dns/message.h Fri Mar 12 05:04:36 2010
@@ -557,6 +557,7 @@
void toWire(MessageRenderer& renderer);
/// \brief Parse a DNS message.
+ void parseHeader(InputBuffer& buffer);
void fromWire(InputBuffer& buffer);
///
More information about the bind10-changes
mailing list