From dc6ecfde622c01ce123e4e3e0bfe32c3f234c8ce Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 25 Aug 2011 06:23:06 +0000 Subject: [PATCH] save the result of is_response(msg) so it can be treated as a invariant by clang --- lib/dns/tsig.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/dns/tsig.c b/lib/dns/tsig.c index 94463e3ecd..dbab157875 100644 --- a/lib/dns/tsig.c +++ b/lib/dns/tsig.c @@ -16,7 +16,7 @@ */ /* - * $Id: tsig.c,v 1.138.136.5 2010/12/09 01:05:28 marka Exp $ + * $Id: tsig.c,v 1.138.136.6 2011/08/25 06:23:06 marka Exp $ */ /*! \file */ #include @@ -709,6 +709,7 @@ dns_tsig_sign(dns_message_t *msg) { isc_result_t ret; unsigned char badtimedata[BADTIMELEN]; unsigned int sigsize = 0; + isc_boolean_t response = is_response(msg); REQUIRE(msg != NULL); REQUIRE(VALID_TSIG_KEY(dns_message_gettsigkey(msg))); @@ -716,7 +717,7 @@ dns_tsig_sign(dns_message_t *msg) { /* * If this is a response, there should be a query tsig. */ - if (is_response(msg) && msg->querytsig == NULL) + if (response && msg->querytsig == NULL) return (DNS_R_EXPECTEDTSIG); dynbuf = NULL; @@ -739,7 +740,7 @@ dns_tsig_sign(dns_message_t *msg) { isc_buffer_init(&databuf, data, sizeof(data)); - if (is_response(msg)) + if (response) tsig.error = msg->querytsigstatus; else tsig.error = dns_rcode_noerror; @@ -768,7 +769,7 @@ dns_tsig_sign(dns_message_t *msg) { /* * If this is a response, digest the query signature. */ - if (is_response(msg)) { + if (response) { dns_rdata_t querytsigrdata = DNS_RDATA_INIT; ret = dns_rdataset_first(msg->querytsig); @@ -888,7 +889,7 @@ dns_tsig_sign(dns_message_t *msg) { digestbits = dst_key_getbits(key->key); if (digestbits != 0) { unsigned int bytes = (digestbits + 1) / 8; - if (is_response(msg) && bytes < querytsig.siglen) + if (response && bytes < querytsig.siglen) bytes = querytsig.siglen; if (bytes > isc_buffer_usedlength(&sigbuf)) bytes = isc_buffer_usedlength(&sigbuf); @@ -990,10 +991,12 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, isc_uint16_t addcount, id; unsigned int siglen; unsigned int alg; + isc_boolean_t response; REQUIRE(source != NULL); REQUIRE(DNS_MESSAGE_VALID(msg)); tsigkey = dns_message_gettsigkey(msg); + response = is_response(msg); REQUIRE(tsigkey == NULL || VALID_TSIG_KEY(tsigkey)); @@ -1015,8 +1018,7 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, * If this is a response and there's no key or query TSIG, there * shouldn't be one on the response. */ - if (is_response(msg) && - (tsigkey == NULL || msg->querytsig == NULL)) + if (response && (tsigkey == NULL || msg->querytsig == NULL)) return (DNS_R_UNEXPECTEDTSIG); mctx = msg->mctx; @@ -1035,7 +1037,7 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, if (ret != ISC_R_SUCCESS) return (ret); dns_rdata_reset(&rdata); - if (is_response(msg)) { + if (response) { ret = dns_rdataset_first(msg->querytsig); if (ret != ISC_R_SUCCESS) return (ret); @@ -1048,7 +1050,7 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, /* * Do the key name and algorithm match that of the query? */ - if (is_response(msg) && + if (response && (!dns_name_equal(keyname, &tsigkey->name) || !dns_name_equal(&tsig.algorithm, &querytsig.algorithm))) { msg->tsigstatus = dns_tsigerror_badkey; @@ -1146,7 +1148,7 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, if (ret != ISC_R_SUCCESS) return (ret); - if (is_response(msg)) { + if (response) { isc_buffer_init(&databuf, data, sizeof(data)); isc_buffer_putuint16(&databuf, querytsig.siglen); isc_buffer_usedregion(&databuf, &r);