]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4841. [bug] Address -fsanitize=undefined warnings. [RT #46786]
authorMark Andrews <marka@isc.org>
Wed, 6 Dec 2017 10:00:14 +0000 (21:00 +1100)
committerMark Andrews <marka@isc.org>
Wed, 6 Dec 2017 10:02:24 +0000 (21:02 +1100)
(cherry picked from commit 9d5a0abe8180b0ca74d6d1f887d832e8cfa088ab)

CHANGES
bin/tests/system/rndc/tests.sh
lib/dns/message.c
lib/dns/name.c
lib/dns/rdata/generic/opt_41.c
lib/isc/inet_aton.c
lib/isc/random.c
lib/isc/tests/random_test.c

diff --git a/CHANGES b/CHANGES
index 11844cfbd22fe723c75388943ad8419c54917a01..6e9b33163b6ef6b721fba0a658395e68e47fa994 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+4841.  [bug]           Address -fsanitize=undefined warnings. [RT #46786]
+
 4840.  [test]          Add tests to cover fallback to using ZSK on inactive
                        KSK. [RT #46787]
 
index 6b811c08ba1ff9b101e7d9eecd395301886697f4..4a1a14bb63031462886ecf8a14ce91ede663daa8 100644 (file)
@@ -571,7 +571,7 @@ n=`expr $n + 1`
 echo " I:wait for the zones to be loaded ($n)"
 ret=1
 try=0
-while test $try -lt 45
+while test $try -lt 100
 do
     sleep 1
     sed -n "$cur,"'$p' < ns6/named.run | grep "any newly configured zones are now loaded" > /dev/null && {
index 1bc7141cb8b22303c246027fa671176d18bc9e85..37e017e585fcd12ae836917e1ec25199a0a2f797 100644 (file)
@@ -4310,8 +4310,10 @@ dns_message_buildopt(dns_message_t *message, dns_rdataset_t **rdatasetp,
                for (i = 0; i < count; i++)  {
                        isc_buffer_putuint16(buf, ednsopts[i].code);
                        isc_buffer_putuint16(buf, ednsopts[i].length);
-                       isc_buffer_putmem(buf, ednsopts[i].value,
-                                         ednsopts[i].length);
+                       if (ednsopts[i].length != 0) {
+                               isc_buffer_putmem(buf, ednsopts[i].value,
+                                                 ednsopts[i].length);
+                       }
                }
                rdata->data = isc_buffer_base(buf);
                rdata->length = len;
index e9bb9f9b57bd0be894ba771e5fdd5b964d236da9..5ff4e464a01466c4ac695a93439d43e716a8e745 100644 (file)
@@ -1045,7 +1045,8 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r) {
                len = (r->length < r2.length) ? r->length : r2.length;
                if (len > DNS_NAME_MAXWIRE)
                        len = DNS_NAME_MAXWIRE;
-               memmove(r2.base, r->base, len);
+               if (len != 0)
+                       memmove(r2.base, r->base, len);
                name->ndata = r2.base;
                name->length = len;
        } else {
@@ -2027,8 +2028,11 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx,
        if (gf) {
                if (target->length - target->used < gp.length)
                        return (ISC_R_NOSPACE);
-               (void)memmove((unsigned char *)target->base + target->used,
-                             gp.ndata, (size_t)gp.length);
+               if (gp.length != 0) {
+                       unsigned char *base = target->base;
+                       (void)memmove(base + target->used, gp.ndata,
+                                     (size_t)gp.length);
+               }
                isc_buffer_add(target, gp.length);
                go |= 0xc000;
                if (target->length - target->used < 2)
@@ -2039,8 +2043,11 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx,
        } else {
                if (target->length - target->used < name->length)
                        return (ISC_R_NOSPACE);
-               (void)memmove((unsigned char *)target->base + target->used,
-                             name->ndata, (size_t)name->length);
+               if (name->length != 0) {
+                       unsigned char *base = target->base;
+                       (void)memmove(base + target->used, name->ndata,
+                                     (size_t)name->length);
+               }
                isc_buffer_add(target, name->length);
                dns_compress_add(cctx, name, name, offset);
        }
@@ -2512,7 +2519,8 @@ dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target)
        ndata = (unsigned char *)target->base + target->used;
        dest->ndata = target->base;
 
-       memmove(ndata, source->ndata, source->length);
+       if (source->length != 0)
+               memmove(ndata, source->ndata, source->length);
 
        dest->ndata = ndata;
        dest->labels = source->labels;
index 71e7be2d3d74ba050b9eeead2ab2fffee045fa4b..a124c3dd736dcad993e73e4642c765233ffa791b 100644 (file)
@@ -98,6 +98,8 @@ fromwire_opt(ARGS_FROMWIRE) {
        UNUSED(options);
 
        isc_buffer_activeregion(source, &sregion);
+       if (sregion.length == 0)
+               return (ISC_R_SUCCESS);
        total = 0;
        while (sregion.length != 0) {
                if (sregion.length < 4)
index 83e6334362c312d3f18b91c26a686600eed5a027..403936a52c2d2b6fec8e46e4f167a4eda2f9b8cf 100644 (file)
@@ -82,8 +82,8 @@ isc_net_aton(const char *cp, struct in_addr *addr) {
        int base;
        ptrdiff_t n;
        unsigned char c;
-       isc_uint8_t parts[4];
-       isc_uint8_t *pp = parts;
+       isc_uint32_t parts[4];
+       isc_uint32_t *pp = parts;
        int digit;
 
        c = *cp;
@@ -135,7 +135,7 @@ isc_net_aton(const char *cp, struct in_addr *addr) {
                         */
                        if (pp >= parts + 3 || val > 0xffU)
                                return (0);
-                       *pp++ = (isc_uint8_t)val;
+                       *pp++ = val;
                        c = *++cp;
                } else
                        break;
index dcc386dd955172d1649c3d71e8e5eb6c26faecea..e9282749d1a3182a3172a2b45b6b02ef6835c5a4 100644 (file)
@@ -133,7 +133,8 @@ isc_random_get(isc_uint32_t *val) {
         */
 #if RAND_MAX >= 0xfffff
        /* We have at least 20 bits.  Use lower 16 excluding lower most 4 */
-       *val = ((rand() >> 4) & 0xffff) | ((rand() << 12) & 0xffff0000);
+       *val = ((((unsigned int)rand()) & 0xffff0) >> 4) |
+              ((((unsigned int)rand()) & 0xffff0) << 12);
 #elif RAND_MAX >= 0x7fff
        /* We have at least 15 bits.  Use lower 10/11 excluding lower most 4 */
        *val = ((rand() >> 4) & 0x000007ff) | ((rand() << 7) & 0x003ff800) |
index fe9c7b8863042f84cb7160d5b16b8f19532fcaee..d21515284d1e00e1ad3a5fd4407d206e83ac04cb 100644 (file)
@@ -194,14 +194,14 @@ tables_init(void) {
 static isc_uint32_t
 matrix_binaryrank(isc_uint32_t *bits, ssize_t rows, ssize_t cols) {
        ssize_t i, j, k;
-       int rt = 0;
+       unsigned int rt = 0;
        isc_uint32_t rank = 0;
        isc_uint32_t tmp;
 
        for (k = 0; k < rows; k++) {
                i = k;
 
-               while (((bits[i] >> rt) & 1) == 0) {
+               while (rt >= cols || ((bits[i] >> rt) & 1) == 0) {
                        i++;
 
                        if (i < rows)