]> 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>
Wed, 2 Mar 2022 00:06:53 +0000 (11:06 +1100)
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.

(cherry picked from commit b8b99603f117825f409cb2d49bc90ef188749227)

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

index 8e353f1c59a64a2ffeaee6f274d31e73e5e2e5b1..69beef7fbb3af4141c5682ae35b8a38b5e76fdbf 100644 (file)
@@ -111,7 +111,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 acb35d22e614fa4f626ccca699fa13c51fc3f650..f99d8a6c126e9f77f3dd3d3994a5c120c8ac87a6 100644 (file)
@@ -8974,8 +8974,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