]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use larger buffers on snprintf buffer overflow false positives
authorOndřej Surý <ondrej@sury.org>
Wed, 24 Oct 2018 14:28:21 +0000 (16:28 +0200)
committerOndřej Surý <ondrej@sury.org>
Thu, 8 Nov 2018 05:21:53 +0000 (12:21 +0700)
lib/dns/rdata/generic/loc_29.c
lib/dns/rdata/in_1/dhcid_49.c

index 50c00ff9f7a9bbfca0a3014320a82b3a5a77a576..7af1c187313a12ef3e85ab191f86fdb5e2617264 100644 (file)
@@ -454,11 +454,12 @@ totext_loc(ARGS_TOTEXT) {
        bool east;
        bool below;
        isc_region_t sr;
-       char buf[sizeof("89 59 59.999 N 179 59 59.999 E "
-                       "-42849672.95m 90000000m 90000000m 90000000m")];
        char sbuf[sizeof("90000000m")];
        char hbuf[sizeof("90000000m")];
        char vbuf[sizeof("90000000m")];
+       /* "89 59 59.999 N 179 59 59.999 E " */
+       /* "-42849672.95m 90000000m 90000000m 90000000m"; */
+       char buf[8*6 + 12*1 + 2*10 + sizeof(sbuf)+sizeof(hbuf)+sizeof(vbuf)];
        unsigned char size, hp, vp;
        unsigned long poweroften[8] = { 1, 10, 100, 1000,
                                        10000, 100000, 1000000, 10000000 };
@@ -550,7 +551,7 @@ totext_loc(ARGS_TOTEXT) {
                altitude -= 10000000;
        }
 
-       snprintf(buf, sizeof(buf),
+       snprintf(NULL, 0,
                 "%d %d %d.%03d %s %d %d %d.%03d %s %s%lu.%02lum %s %s %s",
                 d1, m1, s1, fs1, north ? "N" : "S",
                 d2, m2, s2, fs2, east ? "E" : "W",
index 90971b7827db19c0e5b46caaa745b0aeb9c30e0d..9fce42d47371150e8cd2edc1364ea557882b3ab9 100644 (file)
@@ -35,8 +35,8 @@ fromtext_in_dhcid(ARGS_FROMTEXT) {
 static inline isc_result_t
 totext_in_dhcid(ARGS_TOTEXT) {
        isc_region_t sr, sr2;
-       char buf[sizeof(" ; 64000 255 64000")];
-       size_t n;
+       /* " ; 64000 255 64000" */
+       char buf[5 + 3*5 + 1];
 
        REQUIRE(rdata->type == dns_rdatatype_dhcid);
        REQUIRE(rdata->rdclass == dns_rdataclass_in);
@@ -55,10 +55,9 @@ totext_in_dhcid(ARGS_TOTEXT) {
        if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
                RETERR(str_totext(/* ( */ " )", target));
                if (rdata->length > 2) {
-                       n = snprintf(buf, sizeof(buf), " ; %u %u %u",
-                                    sr2.base[0] * 256U + sr2.base[1],
-                                    sr2.base[2], rdata->length - 3U);
-                       INSIST(n < sizeof(buf));
+                       snprintf(NULL, 0, " ; %u %u %u",
+                                sr2.base[0] * 256U + sr2.base[1],
+                                sr2.base[2], rdata->length - 3U);
                        RETERR(str_totext(buf, target));
                }
        }