mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
1193. [bug] dig +besteffort parsing didn't handle packet
truncation. dns_message_parse() has new flag DNS_MESSAGE_IGNORETRUNCATION.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: message.c,v 1.206 2002/02/11 02:03:23 marka Exp $ */
|
||||
/* $Id: message.c,v 1.207 2002/02/12 02:10:32 marka Exp $ */
|
||||
|
||||
/***
|
||||
*** Imports
|
||||
@@ -942,7 +942,6 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
|
||||
isc_boolean_t free_name;
|
||||
isc_boolean_t best_effort;
|
||||
isc_boolean_t seen_problem;
|
||||
isc_buffer_t save = *source;
|
||||
|
||||
section = &msg->sections[DNS_SECTION_QUESTION];
|
||||
|
||||
@@ -954,7 +953,6 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
|
||||
rdatalist = NULL;
|
||||
|
||||
for (count = 0; count < msg->counts[DNS_SECTION_QUESTION]; count++) {
|
||||
save = *source;
|
||||
name = isc_mempool_get(msg->namepool);
|
||||
if (name == NULL)
|
||||
return (ISC_R_NOMEMORY);
|
||||
@@ -1074,10 +1072,6 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
cleanup:
|
||||
if (result == ISC_R_UNEXPECTEDEND && best_effort) {
|
||||
*source = save;
|
||||
result = DNS_R_RECOVERABLE;
|
||||
}
|
||||
if (rdataset != NULL) {
|
||||
INSIST(!dns_rdataset_isassociated(rdataset));
|
||||
isc_mempool_put(msg->rdspool, rdataset);
|
||||
@@ -1122,7 +1116,6 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
|
||||
isc_boolean_t free_name, free_rdataset;
|
||||
isc_boolean_t preserve_order, best_effort, seen_problem;
|
||||
isc_boolean_t issigzero;
|
||||
isc_buffer_t save = *source;
|
||||
|
||||
preserve_order = ISC_TF(options & DNS_MESSAGEPARSE_PRESERVEORDER);
|
||||
best_effort = ISC_TF(options & DNS_MESSAGEPARSE_BESTEFFORT);
|
||||
@@ -1138,7 +1131,6 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
|
||||
skip_type_search = ISC_FALSE;
|
||||
free_name = ISC_FALSE;
|
||||
free_rdataset = ISC_FALSE;
|
||||
save = *source;
|
||||
|
||||
name = isc_mempool_get(msg->namepool);
|
||||
if (name == NULL)
|
||||
@@ -1482,10 +1474,6 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
cleanup:
|
||||
if (result == ISC_R_UNEXPECTEDEND && best_effort) {
|
||||
*source = save;
|
||||
result = DNS_R_RECOVERABLE;
|
||||
}
|
||||
if (free_name)
|
||||
isc_mempool_put(msg->namepool, name);
|
||||
if (free_rdataset)
|
||||
@@ -1504,12 +1492,14 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
|
||||
isc_uint16_t tmpflags;
|
||||
isc_buffer_t origsource;
|
||||
isc_boolean_t seen_problem;
|
||||
isc_boolean_t ignore_tc;
|
||||
|
||||
REQUIRE(DNS_MESSAGE_VALID(msg));
|
||||
REQUIRE(source != NULL);
|
||||
REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
|
||||
|
||||
seen_problem = ISC_FALSE;
|
||||
ignore_tc = ISC_TF(options & DNS_MESSAGEPARSE_IGNORETRUNCATION);
|
||||
|
||||
origsource = *source;
|
||||
|
||||
@@ -1541,6 +1531,8 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
|
||||
dns_decompress_setmethods(&dctx, DNS_COMPRESS_GLOBAL14);
|
||||
|
||||
ret = getquestions(source, msg, &dctx, options);
|
||||
if (ret == ISC_R_UNEXPECTEDEND && ignore_tc)
|
||||
goto truncated;
|
||||
if (ret == DNS_R_RECOVERABLE) {
|
||||
seen_problem = ISC_TRUE;
|
||||
ret = ISC_R_SUCCESS;
|
||||
@@ -1550,6 +1542,8 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
|
||||
msg->question_ok = 1;
|
||||
|
||||
ret = getsection(source, msg, &dctx, DNS_SECTION_ANSWER, options);
|
||||
if (ret == ISC_R_UNEXPECTEDEND && ignore_tc)
|
||||
goto truncated;
|
||||
if (ret == DNS_R_RECOVERABLE) {
|
||||
seen_problem = ISC_TRUE;
|
||||
ret = ISC_R_SUCCESS;
|
||||
@@ -1558,6 +1552,8 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
|
||||
return (ret);
|
||||
|
||||
ret = getsection(source, msg, &dctx, DNS_SECTION_AUTHORITY, options);
|
||||
if (ret == ISC_R_UNEXPECTEDEND && ignore_tc)
|
||||
goto truncated;
|
||||
if (ret == DNS_R_RECOVERABLE) {
|
||||
seen_problem = ISC_TRUE;
|
||||
ret = ISC_R_SUCCESS;
|
||||
@@ -1566,6 +1562,8 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
|
||||
return (ret);
|
||||
|
||||
ret = getsection(source, msg, &dctx, DNS_SECTION_ADDITIONAL, options);
|
||||
if (ret == ISC_R_UNEXPECTEDEND && ignore_tc)
|
||||
goto truncated;
|
||||
if (ret == DNS_R_RECOVERABLE) {
|
||||
seen_problem = ISC_TRUE;
|
||||
ret = ISC_R_SUCCESS;
|
||||
@@ -1581,6 +1579,7 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
|
||||
r.length);
|
||||
}
|
||||
|
||||
truncated:
|
||||
if ((options & DNS_MESSAGEPARSE_CLONEBUFFER) == 0)
|
||||
isc_buffer_usedregion(&origsource, &msg->saved);
|
||||
else {
|
||||
@@ -1593,6 +1592,8 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
|
||||
msg->free_saved = 1;
|
||||
}
|
||||
|
||||
if (ret == ISC_R_UNEXPECTEDEND && ignore_tc)
|
||||
return (DNS_R_RECOVERABLE);
|
||||
if (seen_problem == ISC_TRUE)
|
||||
return (DNS_R_RECOVERABLE);
|
||||
return (ISC_R_SUCCESS);
|
||||
|
Reference in New Issue
Block a user