]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Prevent arithmetic overflow of 'i' in master.c:generate
authorMark Andrews <marka@isc.org>
Thu, 3 Mar 2022 22:37:39 +0000 (09:37 +1100)
committerMark Andrews <marka@isc.org>
Fri, 1 Apr 2022 07:56:52 +0000 (07:56 +0000)
the value of 'i' in generate could overflow when adding 'step' to
it in the 'for' loop.  Use an unsigned int for 'i' which will give
an additional bit and prevent the overflow.  The inputs are both
less than 2^31 and and the result will be less than 2^32-1.

lib/dns/master.c

index 4f0dce775fe851f895e8d17120e9436e3068ab9e..7399729161d3443bb921262e03191a34691d86f4 100644 (file)
@@ -790,7 +790,8 @@ generate(dns_loadctx_t *lctx, char *range, char *lhs, char *gtype, char *rhs,
        isc_buffer_t target;
        isc_result_t result;
        isc_textregion_t r;
-       int i, n, start, stop, step = 0;
+       int n, start, stop, step = 0;
+       unsigned int i;
        dns_incctx_t *ictx;
        char dummy[2];
 
@@ -845,7 +846,7 @@ generate(dns_loadctx_t *lctx, char *range, char *lhs, char *gtype, char *rhs,
                goto insist_cleanup;
        }
 
-       for (i = start; i <= stop; i += step) {
+       for (i = start; i <= (unsigned int)stop; i += step) {
                result = genname(lhs, i, lhsbuf, DNS_MASTER_LHS);
                if (result != ISC_R_SUCCESS) {
                        goto error_cleanup;