]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use unsigned arithmetic when shifting by 24
authorMark Andrews <marka@isc.org>
Mon, 28 Feb 2022 02:43:20 +0000 (13:43 +1100)
committerMark Andrews <marka@isc.org>
Tue, 1 Mar 2022 23:36:00 +0000 (23:36 +0000)
By default C promotes short unsigned values to signed int which
leads to undefined behaviour when the value is shifted by too much.
Force unsigned arithmetic to be perform by explicitly casting to a
unsigned type.

lib/dns/journal.c
lib/dns/rbtdb.c
lib/dns/soa.c

index 859669c92fffe562f61c027606960f386c6abcee..89ac28c4f92c869860d5119aa89cfde9e8ed5606 100644 (file)
@@ -112,7 +112,8 @@ index_to_disk(dns_journal_t *);
 
 static inline uint32_t
 decode_uint32(unsigned char *p) {
-       return ((p[0] << 24) + (p[1] << 16) + (p[2] << 8) + (p[3] << 0));
+       return (((uint32_t)p[0] << 24) + ((uint32_t)p[1] << 16) +
+               ((uint32_t)p[2] << 8) + ((uint32_t)p[3] << 0));
 }
 
 static inline void
index ae34ef28e25558f924c3bfb75e984e5176ad4313..7abbace2cd5f079134d644fee9644156dd89f017 100644 (file)
@@ -8517,8 +8517,9 @@ rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
 #if DNS_RDATASET_FIXED
        if ((rdataset->attributes & DNS_RDATASETATTR_LOADORDER) != 0) {
                unsigned int offset;
-               offset = (raw[0] << 24) + (raw[1] << 16) + (raw[2] << 8) +
-                        raw[3];
+               offset = ((unsigned int)raw[0] << 24) +
+                        ((unsigned int)raw[1] << 16) +
+                        ((unsigned int)raw[2] << 8) + (unsigned int)raw[3];
                raw = rdataset->private3;
                raw += offset;
        }
index d02be34e863d5e22089efed8657552e461c6cd16..82edfd437ed5f48ccd08c0a0ce2a0145bac3e227 100644 (file)
@@ -25,7 +25,8 @@
 
 static inline uint32_t
 decode_uint32(unsigned char *p) {
-       return ((p[0] << 24) + (p[1] << 16) + (p[2] << 8) + (p[3] << 0));
+       return (((uint32_t)p[0] << 24) + ((uint32_t)p[1] << 16) +
+               ((uint32_t)p[2] << 8) + ((uint32_t)p[3] << 0));
 }
 
 static inline void