From a8aa1dbbe1070705b8a74db4963dd76d4ae4992b Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Wed, 11 Jun 2025 16:42:43 +0200 Subject: [PATCH] - Fix conditional expressions with parentheses for bitwise and. --- compat/fake-rfc2553.c | 6 +++--- dnstap/dnstap.c | 4 ++-- doc/Changelog | 1 + iterator/iterator.c | 2 +- services/outside_network.c | 6 +++--- sldns/keyraw.c | 2 +- sldns/str2wire.c | 2 +- testcode/dohclient.c | 2 +- util/data/dname.c | 4 ++-- util/data/msgencode.c | 2 +- util/data/msgreply.c | 2 +- validator/validator.c | 4 ++-- 12 files changed, 19 insertions(+), 18 deletions(-) diff --git a/compat/fake-rfc2553.c b/compat/fake-rfc2553.c index 0f0f34f1f..45b703f2b 100644 --- a/compat/fake-rfc2553.c +++ b/compat/fake-rfc2553.c @@ -57,7 +57,7 @@ int getnameinfo(const struct sockaddr *sa, size_t ATTR_UNUSED(salen), char *host } if (host != NULL) { - if (flags & NI_NUMERICHOST) { + if ((flags & NI_NUMERICHOST)) { if (strlcpy(host, inet_ntoa(sin->sin_addr), hostlen) >= hostlen) return (EAI_MEMORY); @@ -168,7 +168,7 @@ getaddrinfo(const char *hostname, const char *servname, port = 0; } - if (hints && hints->ai_flags & AI_PASSIVE) { + if (hints && (hints->ai_flags & AI_PASSIVE)) { addr = htonl(0x00000000); if (hostname && inet_aton(hostname, &in) != 0) addr = in.s_addr; @@ -193,7 +193,7 @@ getaddrinfo(const char *hostname, const char *servname, } /* Don't try DNS if AI_NUMERICHOST is set */ - if (hints && hints->ai_flags & AI_NUMERICHOST) + if (hints && (hints->ai_flags & AI_NUMERICHOST)) return (EAI_NONAME); hp = gethostbyname(hostname); diff --git a/dnstap/dnstap.c b/dnstap/dnstap.c index 071fd0895..3b2730182 100644 --- a/dnstap/dnstap.c +++ b/dnstap/dnstap.c @@ -542,7 +542,7 @@ dt_msg_send_outside_query(struct dt_env *env, qflags = sldns_buffer_read_u16_at(qmsg, 2); /* type */ - if (qflags & BIT_RD) { + if ((qflags & BIT_RD)) { if (!env->log_forwarder_query_messages) return; dt_msg_init(env, &dm, DNSTAP__MESSAGE__TYPE__FORWARDER_QUERY); @@ -599,7 +599,7 @@ dt_msg_send_outside_response(struct dt_env *env, qflags = ntohs(qflags); /* type */ - if (qflags & BIT_RD) { + if ((qflags & BIT_RD)) { if (!env->log_forwarder_response_messages) return; dt_msg_init(env, &dm, DNSTAP__MESSAGE__TYPE__FORWARDER_RESPONSE); diff --git a/doc/Changelog b/doc/Changelog index 34c2fdcae..432c99313 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ 11 June 2025: Wouter - Fix bitwise operators in conditional expressions with parentheses. + - Fix conditional expressions with parentheses for bitwise and. 5 June 2025: Wouter - Fix unbound-anchor certificate file read for line ends and end of diff --git a/iterator/iterator.c b/iterator/iterator.c index 320faf734..0bf5523c5 100644 --- a/iterator/iterator.c +++ b/iterator/iterator.c @@ -4159,7 +4159,7 @@ processFinished(struct module_qstate* qstate, struct iter_qstate* iq, /* store message with the finished prepended items, * but only if we did recursion. The nonrecursion referral * from cache does not need to be stored in the msg cache. */ - if(!qstate->no_cache_store && qstate->query_flags&BIT_RD) { + if(!qstate->no_cache_store && (qstate->query_flags&BIT_RD)) { iter_dns_store(qstate->env, &qstate->qinfo, iq->response->rep, 0, qstate->prefetch_leeway, iq->dp&&iq->dp->has_parent_side_NS, diff --git a/services/outside_network.c b/services/outside_network.c index 0d7ec8905..2b7f7d0a2 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -2827,7 +2827,7 @@ serviced_perturb_qname(struct ub_randstate* rnd, uint8_t* qbuf, size_t len) random = ub_random(rnd); bits = 30; } - if(random & 0x1) { + if((random & 0x1)) { *d = (uint8_t)toupper((unsigned char)*d); } else { *d = (uint8_t)tolower((unsigned char)*d); @@ -2890,9 +2890,9 @@ serviced_encode(struct serviced_query* sq, sldns_buffer* buff, int with_edns) edns.opt_list_inplace_cb_out = NULL; edns.udp_size = serviced_query_udp_size(sq, sq->status); edns.bits = 0; - if(sq->dnssec & EDNS_DO) + if((sq->dnssec & EDNS_DO)) edns.bits = EDNS_DO; - if(sq->dnssec & BIT_CD) + if((sq->dnssec & BIT_CD)) LDNS_CD_SET(sldns_buffer_begin(buff)); if (sq->ssl_upstream && sq->padding_block_size) { padding_option.opt_code = LDNS_EDNS_PADDING; diff --git a/sldns/keyraw.c b/sldns/keyraw.c index 90a6e8533..cb6ed0387 100644 --- a/sldns/keyraw.c +++ b/sldns/keyraw.c @@ -124,7 +124,7 @@ uint16_t sldns_calc_keytag_raw(uint8_t* key, size_t keysize) size_t i; uint32_t ac32 = 0; for (i = 0; i < keysize; ++i) { - ac32 += (i & 1) ? key[i] : key[i] << 8; + ac32 += ((i & 1)) ? key[i] : key[i] << 8; } ac32 += (ac32 >> 16) & 0xFFFF; return (uint16_t) (ac32 & 0xFFFF); diff --git a/sldns/str2wire.c b/sldns/str2wire.c index becd6d385..392fc8f1d 100644 --- a/sldns/str2wire.c +++ b/sldns/str2wire.c @@ -857,7 +857,7 @@ rrinternal_parse_rdata(sldns_buffer* strbuf, char* token, size_t token_len, while (rdata_len && *rdata != 0) { uint8_t label_len; - if (*rdata & 0xC0) + if ((*rdata & 0xC0)) return LDNS_WIREPARSE_ERR_OK; label_len = *rdata + 1; diff --git a/testcode/dohclient.c b/testcode/dohclient.c index 2c12a5043..5eb523b2e 100644 --- a/testcode/dohclient.c +++ b/testcode/dohclient.c @@ -388,7 +388,7 @@ static int http2_frame_recv_cb(nghttp2_session *session, } if(((frame->hd.type != NGHTTP2_DATA && frame->hd.type != NGHTTP2_HEADERS) || - frame->hd.flags & NGHTTP2_FLAG_END_STREAM) && + (frame->hd.flags & NGHTTP2_FLAG_END_STREAM)) && h2_stream->res_status == 200) { char* pktstr; sldns_buffer_flip(h2_stream->buf); diff --git a/util/data/dname.c b/util/data/dname.c index 2fe7b171d..d29a8e034 100644 --- a/util/data/dname.c +++ b/util/data/dname.c @@ -57,7 +57,7 @@ query_dname_len(sldns_buffer* query) if(sldns_buffer_remaining(query) < 1) return 0; /* parse error, need label len */ labellen = sldns_buffer_read_u8(query); - if(labellen&0xc0) + if((labellen&0xc0)) return 0; /* no compression allowed in queries */ len += labellen + 1; if(len > LDNS_MAX_DOMAINLEN) @@ -79,7 +79,7 @@ dname_valid(uint8_t* dname, size_t maxlen) return 0; /* too short, shortest is '0' root label */ labellen = *dname++; while(labellen) { - if(labellen&0xc0) + if((labellen&0xc0)) return 0; /* no compression ptrs allowed */ len += labellen + 1; if(len >= LDNS_MAX_DOMAINLEN) diff --git a/util/data/msgencode.c b/util/data/msgencode.c index 6d116fb52..d229a7447 100644 --- a/util/data/msgencode.c +++ b/util/data/msgencode.c @@ -1021,7 +1021,7 @@ reply_info_answer_encode(struct query_info* qinf, struct reply_info* rep, flags |= BIT_AA; flags &= ~BIT_AD; } - log_assert(flags & BIT_QR); /* QR bit must be on in our replies */ + log_assert((flags & BIT_QR)); /* QR bit must be on in our replies */ if(udpsize < LDNS_HEADER_SIZE) return 0; /* currently edns does not change during calculations; diff --git a/util/data/msgreply.c b/util/data/msgreply.c index 35d768f9a..090490d7a 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -251,7 +251,7 @@ rdata_copy(sldns_buffer* pkt, struct packed_rrset_data* data, uint8_t* to, *rr_ttl = sldns_read_uint32(rr->ttl_data); /* RFC 2181 Section 8. if msb of ttl is set treat as if zero. */ - if(*rr_ttl & 0x80000000U) + if((*rr_ttl & 0x80000000U)) *rr_ttl = 0; if(type == LDNS_RR_TYPE_SOA && section == LDNS_SECTION_AUTHORITY) { /* negative response. see if TTL of SOA record larger than the diff --git a/validator/validator.c b/validator/validator.c index a0550b484..7f8b19263 100644 --- a/validator/validator.c +++ b/validator/validator.c @@ -399,7 +399,7 @@ needs_validation(struct module_qstate* qstate, int ret_rc, * For DNS64 bit_cd signals no dns64 processing, but we want to * provide validation there too */ /* - if(qstate->query_flags & BIT_CD) { + if((qstate->query_flags & BIT_CD)) { verbose(VERB_ALGO, "not validating response due to CD bit"); return 0; } @@ -2594,7 +2594,7 @@ processFinished(struct module_qstate* qstate, struct val_qstate* vq, /* Update rep->reason_bogus as it is the one being cached */ update_reason_bogus(vq->orig_msg->rep, errinf_to_reason_bogus(qstate)); /* store results in cache */ - if(qstate->query_flags&BIT_RD) { + if((qstate->query_flags&BIT_RD)) { /* if secure, this will override cache anyway, no need * to check if from parentNS */ if(!qstate->no_cache_store) { -- 2.47.2