From 47338c2c876970cdd8c0e07532b88bc65bf1ea3c Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 9 Jul 2024 10:29:30 +1000 Subject: [PATCH] Remove unnecessary operations Decrementing optlen immediately before calling continue is unneccesary and inconsistent with the rest of dns_message_pseudosectiontoyaml and dns_message_pseudosectiontotext. Coverity was also reporting an impossible false positive overflow of optlen (CID 499061). 4176 } else if (optcode == DNS_OPT_CLIENT_TAG) { 4177 uint16_t id; 4178 ADD_STRING(target, "; CLIENT-TAG:"); 4179 if (optlen == 2U) { 4180 id = isc_buffer_getuint16(&optbuf); 4181 snprintf(buf, sizeof(buf), " %u\n", id); 4182 ADD_STRING(target, buf); CID 499061: (#1 of 1): Overflowed constant (INTEGER_OVERFLOW) overflow_const: Expression optlen, which is equal to 65534, underflows the type that receives it, an unsigned integer 16 bits wide. 4183 optlen -= 2; 4184 POST(optlen); 4185 continue; 4186 } 4187 } else if (optcode == DNS_OPT_SERVER_TAG) { --- lib/dns/message.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/dns/message.c b/lib/dns/message.c index d1917b30e2..c00d54bffd 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -3839,8 +3839,6 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section, id = isc_buffer_getuint16(&optbuf); snprintf(buf, sizeof(buf), " %u\n", id); ADD_STRING(target, buf); - optlen -= 2; - POST(optlen); continue; } } else if (optcode == DNS_OPT_SERVER_TAG) { @@ -3851,8 +3849,6 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section, id = isc_buffer_getuint16(&optbuf); snprintf(buf, sizeof(buf), " %u\n", id); ADD_STRING(target, buf); - optlen -= 2; - POST(optlen); continue; } } else { @@ -4231,8 +4227,6 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, id = isc_buffer_getuint16(&optbuf); snprintf(buf, sizeof(buf), " %u\n", id); ADD_STRING(target, buf); - optlen -= 2; - POST(optlen); continue; } } else if (optcode == DNS_OPT_SERVER_TAG) { @@ -4242,8 +4236,6 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, id = isc_buffer_getuint16(&optbuf); snprintf(buf, sizeof(buf), " %u\n", id); ADD_STRING(target, buf); - optlen -= 2; - POST(optlen); continue; } } else {