]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4748. [cleanup] Sprintf to snprintf coversions. [RT #46132]
authorMark Andrews <marka@isc.org>
Tue, 3 Oct 2017 03:54:19 +0000 (14:54 +1100)
committerMark Andrews <marka@isc.org>
Tue, 3 Oct 2017 03:54:19 +0000 (14:54 +1100)
55 files changed:
CHANGES
bin/dnssec/dnssec-signzone.c
bin/named/server.c
bin/named/statschannel.c
bin/tests/nsecify.c
bin/tests/rwlock_test.c
bin/tests/sock_test.c
lib/dns/dst_api.c
lib/dns/gssapictx.c
lib/dns/private.c
lib/dns/rdata.c
lib/dns/rdata/any_255/tsig_250.c
lib/dns/rdata/ch_3/a_1.c
lib/dns/rdata/generic/afsdb_18.c
lib/dns/rdata/generic/cert_37.c
lib/dns/rdata/generic/csync_62.c
lib/dns/rdata/generic/ds_43.c
lib/dns/rdata/generic/hip_55.c
lib/dns/rdata/generic/ipseckey_45.c
lib/dns/rdata/generic/key_25.c
lib/dns/rdata/generic/keydata_65533.c
lib/dns/rdata/generic/l32_105.c
lib/dns/rdata/generic/l64_106.c
lib/dns/rdata/generic/loc_29.c
lib/dns/rdata/generic/lp_107.c
lib/dns/rdata/generic/mx_15.c
lib/dns/rdata/generic/naptr_35.c
lib/dns/rdata/generic/nid_104.c
lib/dns/rdata/generic/nsec3_50.c
lib/dns/rdata/generic/nsec3param_51.c
lib/dns/rdata/generic/nxt_30.c
lib/dns/rdata/generic/opt_41.c
lib/dns/rdata/generic/rrsig_46.c
lib/dns/rdata/generic/rt_21.c
lib/dns/rdata/generic/sig_24.c
lib/dns/rdata/generic/sink_40.c
lib/dns/rdata/generic/soa_6.c
lib/dns/rdata/generic/sshfp_44.c
lib/dns/rdata/generic/tkey_249.c
lib/dns/rdata/generic/tlsa_52.c
lib/dns/rdata/generic/uri_256.c
lib/dns/rdata/in_1/a6_38.c
lib/dns/rdata/in_1/kx_36.c
lib/dns/rdata/in_1/nsap_22.c
lib/dns/rdata/in_1/px_26.c
lib/dns/rdata/in_1/wks_11.c
lib/isc/httpd.c
lib/isc/inet_ntop.c
lib/isc/log.c
lib/isc/mem.c
lib/isc/task.c
lib/isc/unix/ifiter_ioctl.c
lib/isc/unix/socket.c
lib/isc/win32/socket.c
lib/isccfg/parser.c

diff --git a/CHANGES b/CHANGES
index 9d1d01222375e1f0ca6c0a2c1a3584dd6f1d864e..268140e4b2e7d603771500bf8deb4ee060324ce5 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+4748.  [cleanup]       Sprintf to snprintf coversions. [RT #46132]
+
 4747.  [func]          Synthesis of responses from DNSSEC-verified records.
                        Stage 3 - synthesize NODATA responses. [RT #40138]
 
index 54b19cd58c4643a25def5088954d84e9e16850b0..82985f407d6422e05dcfc4d72e0bc4ddce2da2ff 100644 (file)
@@ -2813,7 +2813,7 @@ writeset(const char *prefix, dns_rdatatype_t type) {
        if (filename == NULL)
                fatal("out of memory");
        if (dsdir != NULL)
-               sprintf(filename, "%s/", dsdir);
+               snprintf(filename, filenamelen, "%s/", dsdir);
        else
                filename[0] = 0;
        strlcat(filename, prefix, filenamelen);
@@ -3490,12 +3490,13 @@ main(int argc, char *argv[]) {
                origin = file;
 
        if (output == NULL) {
+               size_t size;
                free_output = ISC_TRUE;
-               output = isc_mem_allocate(mctx,
-                                         strlen(file) + strlen(".signed") + 1);
+               size = strlen(file) + strlen(".signed") + 1;
+               output = isc_mem_allocate(mctx, size);
                if (output == NULL)
                        fatal("out of memory");
-               sprintf(output, "%s.signed", file);
+               snprintf(output, size, "%s.signed", file);
        }
 
        if (inputformatstr != NULL) {
index f16a05eac219f06c4e0ad29c0fcc1eca7873540d..9a0ab4cc0476d8d802758d18f2dcbe68cb5bbbdd 100644 (file)
@@ -1790,8 +1790,8 @@ dns64_reverse(dns_view_t *view, isc_mem_t *mctx, isc_netaddr_t *na,
              unsigned int prefixlen, const char *server,
              const char *contact)
 {
-       char *cp;
-       char reverse[48+sizeof("ip6.arpa.")];
+       char reverse[48+sizeof("ip6.arpa.")] = { 0 };
+       char buf[sizeof("x.x.")];
        const char *dns64_dbtype[4] = { "_dns64", "dns64", ".", "." };
        const char *sep = ": view ";
        const char *viewname = view->name;
@@ -1814,15 +1814,13 @@ dns64_reverse(dns_view_t *view, isc_mem_t *mctx, isc_netaddr_t *na,
        /*
         * Construct the reverse name of the zone.
         */
-       cp = reverse;
        s6 = na->type.in6.s6_addr;
        while (prefixlen > 0) {
                prefixlen -= 8;
-               sprintf(cp, "%x.%x.", s6[prefixlen/8] & 0xf,
-                       (s6[prefixlen/8] >> 4) & 0xf);
-               cp += 4;
+               snprintf(buf, sizeof(buf), "%x.%x.", s6[prefixlen/8] & 0xf,
+                        (s6[prefixlen/8] >> 4) & 0xf);
+               strlcat(reverse, buf, sizeof(reverse));
        }
-
        strlcat(reverse, "ip6.arpa.", sizeof(reverse));
 
        /*
index 7a31f444e48fc97ecc78e0edcbe190201132ea0e..848d5e0e03723ee3b10c1c1239b137981a19d229 100644 (file)
@@ -1270,8 +1270,8 @@ rdatasetstats_dump(dns_rdatastatstype_t type, isc_uint64_t val, void *arg) {
        case isc_statsformat_json:
 #ifdef HAVE_JSON
                zoneobj = (json_object *) dumparg->arg;
-               sprintf(buf, "%s%s%s", stale ? "#" : "",
-                                      nxrrset ? "!" : "", typestr);
+               snprintf(buf, sizeof(buf), "%s%s%s",
+                        stale ? "#" : "", nxrrset ? "!" : "", typestr);
                obj = json_object_new_int64(val);
                if (obj == NULL)
                        return;
index ec30c21e6c9778b1f093256ad026b6fdf65ba1ba..b420fe60c0900b044626cec036f2b915f00e890a 100644 (file)
@@ -179,7 +179,7 @@ nsecify(char *filename) {
        len = strlen(filename);
        if (len + 4 + 1 > sizeof(newfilename))
                fatal("filename too long");
-       sprintf(newfilename, "%s.new", filename);
+       snprintf(newfilename, sizeof(newfilename), "%s.new", filename);
        result = dns_db_dump(db, NULL, newfilename);
        check_result(result, "dns_db_dump");
        dns_db_detach(&db);
index 44f33e7d5768786de25b7305026e02dc2bd6a10a..781a8804cd9ae210fd0e3d83cbf7f15e44cf40d1 100644 (file)
@@ -109,7 +109,7 @@ main(int argc, char *argv[]) {
        RUNTIME_CHECK(isc_rwlock_init(&lock, 5, 10) == ISC_R_SUCCESS);
 
        for (i = 0; i < nworkers; i++) {
-               sprintf(name, "%02u", i);
+               snprintf(name, sizeof(name), "%02u", i);
                dupname = strdup(name);
                RUNTIME_CHECK(dupname != NULL);
                if (i != 0 && i % 3 == 0)
index 64a518c4c62429817641b21354527fbe65b4bf47..8463414c1c52928b50cfcc8f289139c0a5811d74 100644 (file)
@@ -102,8 +102,8 @@ my_recv(isc_task_t *task, isc_event_t *event) {
         */
        if (strcmp(event->ev_arg, "so2") != 0) {
                region = dev->region;
-               sprintf(buf, "\r\nReceived: %.*s\r\n\r\n",
-                       (int)dev->n, (char *)region.base);
+               snprintf(buf, sizeof(buf), "\r\nReceived: %.*s\r\n\r\n",
+                        (int)dev->n, (char *)region.base);
                region.base = isc_mem_get(mctx, strlen(buf) + 1);
                if (region.base != NULL) {
                        region.length = strlen(buf) + 1;
index 107215ff5183f6cb255fe25b70a704d49660b5fd..76212bf5aad18e5f8b6c3e19033a1d211d5164b3 100644 (file)
@@ -1878,8 +1878,9 @@ buildfilename(dns_name_t *name, dns_keytag_t id,
        len = 1 + 3 + 1 + 5 + strlen(suffix) + 1;
        if (isc_buffer_availablelength(out) < len)
                return (ISC_R_NOSPACE);
-       sprintf((char *) isc_buffer_used(out), "+%03d+%05d%s", alg, id,
-               suffix);
+       snprintf((char *) isc_buffer_used(out),
+                (int)isc_buffer_availablelength(out),
+                "+%03d+%05d%s", alg, id, suffix);
        isc_buffer_add(out, len);
 
        return (ISC_R_SUCCESS);
index d2fe9de23c61409a54349355416e40a980bafb32..b15d3db1de28a3bf1c71c10a7f4c9806935f1e39 100644 (file)
@@ -695,10 +695,14 @@ dst_gssapi_acceptctx(gss_cred_id_t cred,
                 */
                const char *old = getenv("KRB5_KTNAME");
                if (old == NULL || strcmp(old, gssapi_keytab) != 0) {
-                       char *kt = malloc(strlen(gssapi_keytab) + 13);
+                       size_t size;
+                       char *kt;
+
+                       size = strlen(gssapi_keytab) + 13;
+                       kt = malloc(size);
                        if (kt == NULL)
                                return (ISC_R_NOMEMORY);
-                       sprintf(kt, "KRB5_KTNAME=%s", gssapi_keytab);
+                       snprintf(kt, size, "KRB5_KTNAME=%s", gssapi_keytab);
                        if (putenv(kt) != 0)
                                return (ISC_R_NOMEMORY);
                }
index 02e0280b4b7ce9079ccc9c0fb32085f022a5a1db..a305d8a22b15c54fa88fd033bb12bd0a7643bc7e 100644 (file)
@@ -351,7 +351,7 @@ dns_private_totext(dns_rdata_t *private, isc_buffer_t *buf) {
                        isc_buffer_putstr(buf, "Signing with ");
 
                dns_secalg_format(alg, algbuf, sizeof(algbuf));
-               sprintf(keybuf, "key %d/%s", keyid, algbuf);
+               snprintf(keybuf, sizeof(keybuf), "key %d/%s", keyid, algbuf);
                isc_buffer_putstr(buf, keybuf);
        } else
                return (ISC_R_NOTFOUND);
index f1c86e2dbf6a6a73eaed42459955e44f1a22b513..27b959ea0198090c5040bc67d568dacc69bb1caa 100644 (file)
@@ -522,7 +522,7 @@ typemap_totext(isc_region_t *sr, dns_rdata_textctx_t *tctx,
                                        RETERR(dns_rdatatype_totext(t, target));
                                } else {
                                        char buf[sizeof("TYPE65535")];
-                                       sprintf(buf, "TYPE%u", t);
+                                       snprintf(buf, sizeof(buf), "TYPE%u", t);
                                        RETERR(str_totext(buf, target));
                                }
                        }
index 96bae4bb3442f752c509f04a48320a4ab13de826..30a0cff42f92fabfa9e9dc0dd084aa3b58a8ba2f 100644 (file)
@@ -174,7 +174,7 @@ totext_any_tsig(ARGS_TOTEXT) {
         */
        n = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%u ", n);
+       snprintf(buf, sizeof(buf), "%u ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -182,7 +182,7 @@ totext_any_tsig(ARGS_TOTEXT) {
         */
        n = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%u", n);
+       snprintf(buf, sizeof(buf), "%u", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -210,7 +210,7 @@ totext_any_tsig(ARGS_TOTEXT) {
         */
        n = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%u ", n);
+       snprintf(buf, sizeof(buf), "%u ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -225,7 +225,7 @@ totext_any_tsig(ARGS_TOTEXT) {
         */
        n = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, " %u ", n);
+       snprintf(buf, sizeof(buf), " %u ", n);
        RETERR(str_totext(buf, target));
 
        /*
index b56d711cac7dc0228c0d6256073b911c3a275e1c..1f2a0b5af2701ffbef3a6bae35756640d9905e65 100644 (file)
@@ -80,7 +80,7 @@ totext_ch_a(ARGS_TOTEXT) {
        sub = name_prefix(&name, tctx->origin, &prefix);
        RETERR(dns_name_totext(&prefix, sub, target));
 
-       sprintf(buf, "%o", addr); /* note octal */
+       snprintf(buf, sizeof(buf), "%o", addr); /* note octal */
        RETERR(str_totext(" ", target));
        return (str_totext(buf, target));
 }
index ae13042c6fb048c68bc259d17c19214a656704a6..66ee99d646eb55d1bc262646aea48be8d46d44ba 100644 (file)
@@ -77,7 +77,7 @@ totext_afsdb(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u ", num);
+       snprintf(buf, sizeof(buf), "%u ", num);
        RETERR(str_totext(buf, target));
        dns_name_fromregion(&name, &region);
        sub = name_prefix(&name, tctx->origin, &prefix);
index 3b01ce2f269f89cccb16f6c07a2cb35a3a3a1467..b7743b9cba27153f765a3c15407b85e60c593a61 100644 (file)
@@ -85,7 +85,7 @@ totext_cert(ARGS_TOTEXT) {
         */
        n = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%u ", n);
+       snprintf(buf, sizeof(buf), "%u ", n);
        RETERR(str_totext(buf, target));
 
        /*
index 66a21bb6912edd4cbb33fc128dcf571ab1da5c0a..324c4c16e547b8aaedfa8cfabf6e3274944a4505 100644 (file)
@@ -56,14 +56,14 @@ totext_csync(ARGS_TOTEXT) {
 
        num = uint32_fromregion(&sr);
        isc_region_consume(&sr, 4);
-       sprintf(buf, "%lu", num);
+       snprintf(buf, sizeof(buf), "%lu", num);
        RETERR(str_totext(buf, target));
 
        RETERR(str_totext(" ", target));
 
        num = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%lu", num);
+       snprintf(buf, sizeof(buf), "%lu", num);
        RETERR(str_totext(buf, target));
 
        return (typemap_totext(&sr, NULL, target));
index 58d5410f99ffd92d66bf71d99cdc15a286234d94..a7acebceea3016af0fc08ffe1a1dbacd2de19a56 100644 (file)
@@ -111,7 +111,7 @@ generic_totext_ds(ARGS_TOTEXT) {
         */
        n = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%u ", n);
+       snprintf(buf, sizeof(buf), "%u ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -119,7 +119,7 @@ generic_totext_ds(ARGS_TOTEXT) {
         */
        n = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u ", n);
+       snprintf(buf, sizeof(buf), "%u ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -127,7 +127,7 @@ generic_totext_ds(ARGS_TOTEXT) {
         */
        n = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u", n);
+       snprintf(buf, sizeof(buf), "%u", n);
        RETERR(str_totext(buf, target));
 
        /*
index 034deb584a9fa90a4206c4e7cf5e1910816bcfc5..4f1689327cff384303ebddf326fd7d3205e79626 100644 (file)
@@ -140,7 +140,7 @@ totext_hip(ARGS_TOTEXT) {
        /*
         * Algorithm
         */
-       sprintf(buf, "%u ", algorithm);
+       snprintf(buf, sizeof(buf), "%u ", algorithm);
        RETERR(str_totext(buf, target));
 
        /*
index 5a9eeab899c8e13673b158ad09610bdb4456451f..5ea3ae18cd52544fae5f045fb538189d34de4861 100644 (file)
@@ -134,7 +134,7 @@ totext_ipseckey(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint8_fromregion(&region);
        isc_region_consume(&region, 1);
-       sprintf(buf, "%u ", num);
+       snprintf(buf, sizeof(buf), "%u ", num);
        RETERR(str_totext(buf, target));
 
        /*
@@ -142,7 +142,7 @@ totext_ipseckey(ARGS_TOTEXT) {
         */
        gateway = uint8_fromregion(&region);
        isc_region_consume(&region, 1);
-       sprintf(buf, "%u ", gateway);
+       snprintf(buf, sizeof(buf), "%u ", gateway);
        RETERR(str_totext(buf, target));
 
        /*
@@ -150,7 +150,7 @@ totext_ipseckey(ARGS_TOTEXT) {
         */
        num = uint8_fromregion(&region);
        isc_region_consume(&region, 1);
-       sprintf(buf, "%u ", num);
+       snprintf(buf, sizeof(buf), "%u ", num);
        RETERR(str_totext(buf, target));
 
        /*
index 97275e01d0c2e21936b1bc6f6adb792f12627c47..c63b303ac229ef6fa9f2f901b4c94322720198b7 100644 (file)
@@ -85,7 +85,7 @@ generic_totext_key(ARGS_TOTEXT) {
        /* flags */
        flags = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%u", flags);
+       snprintf(buf, sizeof(buf), "%u", flags);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
        if ((flags & DNS_KEYFLAG_KSK) != 0) {
@@ -98,14 +98,14 @@ generic_totext_key(ARGS_TOTEXT) {
 
 
        /* protocol */
-       sprintf(buf, "%u", sr.base[0]);
+       snprintf(buf, sizeof(buf), "%u", sr.base[0]);
        isc_region_consume(&sr, 1);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
 
        /* algorithm */
        algorithm = sr.base[0];
-       sprintf(buf, "%u", algorithm);
+       snprintf(buf, sizeof(buf), "%u", algorithm);
        isc_region_consume(&sr, 1);
        RETERR(str_totext(buf, target));
 
@@ -161,7 +161,8 @@ generic_totext_key(ARGS_TOTEXT) {
                RETERR(str_totext(algbuf, target));
                RETERR(str_totext(" ; key id = ", target));
                dns_rdata_toregion(rdata, &tmpr);
-               sprintf(buf, "%u", dst_region_computeid(&tmpr, algorithm));
+               snprintf(buf, sizeof(buf), "%u",
+                        dst_region_computeid(&tmpr, algorithm));
                RETERR(str_totext(buf, target));
        }
        return (ISC_R_SUCCESS);
index 60933047d4832b2d7058b38c374bc7e3f14d5aa6..6ddf28903369dcec90f084b4351203f671578b75 100644 (file)
@@ -122,7 +122,7 @@ totext_keydata(ARGS_TOTEXT) {
        /* flags */
        flags = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%u", flags);
+       snprintf(buf, sizeof(buf), "%u", flags);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
        if ((flags & DNS_KEYFLAG_KSK) != 0) {
@@ -134,14 +134,14 @@ totext_keydata(ARGS_TOTEXT) {
                keyinfo = "ZSK";
 
        /* protocol */
-       sprintf(buf, "%u", sr.base[0]);
+       snprintf(buf, sizeof(buf), "%u", sr.base[0]);
        isc_region_consume(&sr, 1);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
 
        /* algorithm */
        algorithm = sr.base[0];
-       sprintf(buf, "%u", algorithm);
+       snprintf(buf, sizeof(buf), "%u", algorithm);
        isc_region_consume(&sr, 1);
        RETERR(str_totext(buf, target));
 
@@ -184,7 +184,8 @@ totext_keydata(ARGS_TOTEXT) {
                dns_rdata_toregion(rdata, &tmpr);
                /* Skip over refresh, addhd, and removehd */
                isc_region_consume(&tmpr, 12);
-               sprintf(buf, "%u", dst_region_computeid(&tmpr, algorithm));
+               snprintf(buf, sizeof(buf), "%u",
+                        dst_region_computeid(&tmpr, algorithm));
                RETERR(str_totext(buf, target));
 
                if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
index 4f77c93d242a6da30a9608b14b46b0a4392560f3..e68ab4fa2af3ac582e475c1a9e0dc3e3f8465d88 100644 (file)
@@ -62,7 +62,7 @@ totext_l32(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
 
        RETERR(str_totext(" ", target));
index 6b4f4c70b3dcfe8fa4f6beaf69d90eb92f6d4d1f..07cc204ab087f84f2899f5034495502fee2de844 100644 (file)
@@ -56,16 +56,16 @@ totext_l64(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
 
        RETERR(str_totext(" ", target));
 
-       sprintf(buf, "%x:%x:%x:%x",
-               region.base[0]<<8 | region.base[1],
-               region.base[2]<<8 | region.base[3],
-               region.base[4]<<8 | region.base[5],
-               region.base[6]<<8 | region.base[7]);
+       snprintf(buf, sizeof(buf), "%x:%x:%x:%x",
+                region.base[0]<<8 | region.base[1],
+                region.base[2]<<8 | region.base[3],
+                region.base[4]<<8 | region.base[5],
+                region.base[6]<<8 | region.base[7]);
        return (str_totext(buf, target));
 }
 
index 7ac98272c08af87e5423de611d52f6a3e0d53923..e2ac0a2332baafdb89b80d459d84746ab567a724 100644 (file)
@@ -478,22 +478,31 @@ totext_loc(ARGS_TOTEXT) {
 
        size = sr.base[1];
        INSIST((size&0x0f) < 10 && (size>>4) < 10);
-       if ((size&0x0f)> 1)
-               sprintf(sbuf, "%lum", (size>>4) * poweroften[(size&0x0f)-2]);
-       else
-               sprintf(sbuf, "0.%02lum", (size>>4) * poweroften[(size&0x0f)]);
+       if ((size&0x0f)> 1) {
+               snprintf(sbuf, sizeof(sbuf),
+                        "%lum", (size>>4) * poweroften[(size&0x0f)-2]);
+       } else {
+               snprintf(sbuf, sizeof(sbuf),
+                        "0.%02lum", (size>>4) * poweroften[(size&0x0f)]);
+       }
        hp = sr.base[2];
        INSIST((hp&0x0f) < 10 && (hp>>4) < 10);
-       if ((hp&0x0f)> 1)
-               sprintf(hbuf, "%lum", (hp>>4) * poweroften[(hp&0x0f)-2]);
-       else
-               sprintf(hbuf, "0.%02lum", (hp>>4) * poweroften[(hp&0x0f)]);
+       if ((hp&0x0f)> 1) {
+               snprintf(hbuf, sizeof(hbuf),
+                       "%lum", (hp>>4) * poweroften[(hp&0x0f)-2]);
+       } else {
+               snprintf(hbuf, sizeof(hbuf),
+                        "0.%02lum", (hp>>4) * poweroften[(hp&0x0f)]);
+       }
        vp = sr.base[3];
        INSIST((vp&0x0f) < 10 && (vp>>4) < 10);
-       if ((vp&0x0f)> 1)
-               sprintf(vbuf, "%lum", (vp>>4) * poweroften[(vp&0x0f)-2]);
-       else
-               sprintf(vbuf, "0.%02lum", (vp>>4) * poweroften[(vp&0x0f)]);
+       if ((vp&0x0f)> 1) {
+               snprintf(vbuf, sizeof(vbuf),
+                        "%lum", (vp>>4) * poweroften[(vp&0x0f)-2]);
+       } else {
+               snprintf(vbuf, sizeof(vbuf),
+                        "0.%02lum", (vp>>4) * poweroften[(vp&0x0f)]);
+       }
        isc_region_consume(&sr, 4);
 
        latitude = uint32_fromregion(&sr);
@@ -542,11 +551,12 @@ totext_loc(ARGS_TOTEXT) {
                altitude -= 10000000;
        }
 
-       sprintf(buf, "%d %d %d.%03d %s %d %d %d.%03d %s %s%ld.%02ldm %s %s %s",
-               d1, m1, s1, fs1, north ? "N" : "S",
-               d2, m2, s2, fs2, east ? "E" : "W",
-               below ? "-" : "", altitude/100, altitude % 100,
-               sbuf, hbuf, vbuf);
+       snprintf(buf, sizeof(buf),
+                "%d %d %d.%03d %s %d %d %d.%03d %s %s%ld.%02ldm %s %s %s",
+                d1, m1, s1, fs1, north ? "N" : "S",
+                d2, m2, s2, fs2, east ? "E" : "W",
+                below ? "-" : "", altitude/100, altitude % 100,
+                sbuf, hbuf, vbuf);
 
        return (str_totext(buf, target));
 }
index e417ffa177da1e7831b7996434dae051d291ed59..2e6772ad1b9a20b83518e80d9cbac8f60952b02a 100644 (file)
@@ -61,7 +61,7 @@ totext_lp(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
 
        RETERR(str_totext(" ", target));
index 61b0ae1984eb26742cfbc9ac8bdcd45148e27d75..ceafb58f52d94fb846c8f5caa1a7b0a022ff976a 100644 (file)
@@ -101,7 +101,7 @@ totext_mx(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
 
        RETERR(str_totext(" ", target));
index e062702a95bcb3b961c8fbfcc149b6da172cf62a..d5c77bd3800f317158f536cf06c48997ef6c9d25 100644 (file)
@@ -200,7 +200,7 @@ totext_naptr(ARGS_TOTEXT) {
         */
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
 
@@ -209,7 +209,7 @@ totext_naptr(ARGS_TOTEXT) {
         */
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
 
index 188e9ee74610c1dd45fd5c4f652a93dffc42642c..0c8ca306e93750a8b2cfa0139681d9dd825f2382 100644 (file)
@@ -56,16 +56,16 @@ totext_nid(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
 
        RETERR(str_totext(" ", target));
 
-       sprintf(buf, "%x:%x:%x:%x",
-               region.base[0]<<8 | region.base[1],
-               region.base[2]<<8 | region.base[3],
-               region.base[4]<<8 | region.base[5],
-               region.base[6]<<8 | region.base[7]);
+       snprintf(buf, sizeof(buf), "%x:%x:%x:%x",
+                region.base[0]<<8 | region.base[1],
+                region.base[2]<<8 | region.base[3],
+                region.base[4]<<8 | region.base[5],
+                region.base[6]<<8 | region.base[7]);
        return (str_totext(buf, target));
 }
 
index 87065e0ad35ff512ab39878b6981bc20f0a61866..8d9d5e94b038fab4dd9d9567985bcd498ff73812 100644 (file)
@@ -115,19 +115,19 @@ totext_nsec3(ARGS_TOTEXT) {
        /* Hash */
        hash = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u ", hash);
+       snprintf(buf, sizeof(buf), "%u ", hash);
        RETERR(str_totext(buf, target));
 
        /* Flags */
        flags = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u ", flags);
+       snprintf(buf, sizeof(buf), "%u ", flags);
        RETERR(str_totext(buf, target));
 
        /* Iterations */
        iterations = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%u ", iterations);
+       snprintf(buf, sizeof(buf), "%u ", iterations);
        RETERR(str_totext(buf, target));
 
        /* Salt */
index 1c283affbf299b8c6183d7e65fbd65f73c18df26..8fe5839bc043115dec6199eda7ffd18fcb892b66 100644 (file)
@@ -109,13 +109,13 @@ totext_nsec3param(ARGS_TOTEXT) {
        iterations = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
 
-       sprintf(buf, "%u ", hash);
+       snprintf(buf, sizeof(buf), "%u ", hash);
        RETERR(str_totext(buf, target));
 
-       sprintf(buf, "%u ", flags);
+       snprintf(buf, sizeof(buf), "%u ", flags);
        RETERR(str_totext(buf, target));
 
-       sprintf(buf, "%u ", iterations);
+       snprintf(buf, sizeof(buf), "%u ", iterations);
        RETERR(str_totext(buf, target));
 
        j = uint8_fromregion(&sr);
index 69412bc5395e4049605cd8967186ee024101b3c0..540c872680489ae237c8b8f909cc0e46fb5e7b01 100644 (file)
@@ -109,7 +109,8 @@ totext_nxt(ARGS_TOTEXT) {
                                                                      target));
                                        } else {
                                                char buf[sizeof("65535")];
-                                               sprintf(buf, "%u", t);
+                                               snprintf(buf, sizeof(buf),
+                                                        "%u", t);
                                                RETERR(str_totext(buf,
                                                                  target));
                                        }
index 48d36ef7d16785b2055ec66e08c400987bff1cf3..71e7be2d3d74ba050b9eeead2ab2fffee045fa4b 100644 (file)
@@ -56,7 +56,7 @@ totext_opt(ARGS_TOTEXT) {
                isc_region_consume(&r, 2);
                length = uint16_fromregion(&r);
                isc_region_consume(&r, 2);
-               sprintf(buf, "%u %u", option, length);
+               snprintf(buf, sizeof(buf), "%u %u", option, length);
                RETERR(str_totext(buf, target));
                INSIST(r.length >= length);
                if (length > 0) {
index a8920c0b7ab5972d65e50db78691a903befdf23d..b147f866212445817e3c5a22c37a3beb4eb1700b 100644 (file)
@@ -145,7 +145,7 @@ fromtext_rrsig(ARGS_FROMTEXT) {
 static inline isc_result_t
 totext_rrsig(ARGS_TOTEXT) {
        isc_region_t sr;
-       char buf[sizeof("4294967295")];
+       char buf[sizeof("4294967295")]; /* Also TYPE65000. */
        dns_rdatatype_t covered;
        unsigned long ttl;
        unsigned long when;
@@ -170,7 +170,7 @@ totext_rrsig(ARGS_TOTEXT) {
        if (dns_rdatatype_isknown(covered) && covered != 0) {
                RETERR(dns_rdatatype_totext(covered, target));
        } else {
-               sprintf(buf, "TYPE%u", covered);
+               snprintf(buf, sizeof(buf), "TYPE%u", covered);
                RETERR(str_totext(buf, target));
        }
        RETERR(str_totext(" ", target));
@@ -178,7 +178,7 @@ totext_rrsig(ARGS_TOTEXT) {
        /*
         * Algorithm.
         */
-       sprintf(buf, "%u", sr.base[0]);
+       snprintf(buf, sizeof(buf), "%u", sr.base[0]);
        isc_region_consume(&sr, 1);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
@@ -186,7 +186,7 @@ totext_rrsig(ARGS_TOTEXT) {
        /*
         * Labels.
         */
-       sprintf(buf, "%u", sr.base[0]);
+       snprintf(buf, sizeof(buf), "%u", sr.base[0]);
        isc_region_consume(&sr, 1);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
@@ -196,7 +196,7 @@ totext_rrsig(ARGS_TOTEXT) {
         */
        ttl = uint32_fromregion(&sr);
        isc_region_consume(&sr, 4);
-       sprintf(buf, "%lu", ttl);
+       snprintf(buf, sizeof(buf), "%lu", ttl);
        RETERR(str_totext(buf, target));
 
        if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
@@ -224,7 +224,7 @@ totext_rrsig(ARGS_TOTEXT) {
         */
        foot = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%lu", foot);
+       snprintf(buf, sizeof(buf), "%lu", foot);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
 
index 34d28cd60a0c2eb86bd59616bde32cdc7baea265..47b80a4a3d4c87058d6e44d96cf9f900cd85ffc6 100644 (file)
@@ -72,7 +72,7 @@ totext_rt(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
        dns_name_fromregion(&name, &region);
index 699210614afa4842acb9f80aac72668953839903..968de07dfd9d65d8cadd627fca00708412e02a21 100644 (file)
@@ -146,7 +146,7 @@ totext_sig(ARGS_TOTEXT) {
        if (dns_rdatatype_isknown(covered) && covered != 0) {
                RETERR(dns_rdatatype_totext(covered, target));
        } else {
-               sprintf(buf, "%u", covered);
+               snprintf(buf, sizeof(buf), "%u", covered);
                RETERR(str_totext(buf, target));
        }
        RETERR(str_totext(" ", target));
@@ -154,7 +154,7 @@ totext_sig(ARGS_TOTEXT) {
        /*
         * Algorithm.
         */
-       sprintf(buf, "%u", sr.base[0]);
+       snprintf(buf, sizeof(buf), "%u", sr.base[0]);
        isc_region_consume(&sr, 1);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
@@ -162,7 +162,7 @@ totext_sig(ARGS_TOTEXT) {
        /*
         * Labels.
         */
-       sprintf(buf, "%u", sr.base[0]);
+       snprintf(buf, sizeof(buf), "%u", sr.base[0]);
        isc_region_consume(&sr, 1);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
@@ -172,7 +172,7 @@ totext_sig(ARGS_TOTEXT) {
         */
        ttl = uint32_fromregion(&sr);
        isc_region_consume(&sr, 4);
-       sprintf(buf, "%lu", ttl);
+       snprintf(buf, sizeof(buf), "%lu", ttl);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
 
@@ -200,7 +200,7 @@ totext_sig(ARGS_TOTEXT) {
         */
        foot = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%lu", foot);
+       snprintf(buf, sizeof(buf), "%lu", foot);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
 
index 0ab8cd6dc8bd5fc78584227535f8f88b5dd9a88f..ce61a1ff16a1010e70701c67cc3e09bca31bf0df 100644 (file)
@@ -67,7 +67,7 @@ totext_sink(ARGS_TOTEXT) {
        isc_region_consume(&sr, 1);
        subcoding = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u %u %u", meaning, coding, subcoding);
+       snprintf(buf, sizeof(buf), "%u %u %u", meaning, coding, subcoding);
        RETERR(str_totext(buf, target));
 
        if (sr.length == 0U)
index 3a0221e262d1994000b125925dc0f62634bfda12..ef73e5d2fa1bc1ac8264a99ab6f12ae3ba281299 100644 (file)
@@ -128,7 +128,7 @@ totext_soa(ARGS_TOTEXT) {
                unsigned long num;
                num = uint32_fromregion(&dregion);
                isc_region_consume(&dregion, 4);
-               sprintf(buf, comm ? "%-10lu ; " : "%lu", num);
+               snprintf(buf, sizeof(buf), comm ? "%-10lu ; " : "%lu", num);
                RETERR(str_totext(buf, target));
                if (comm) {
                        RETERR(str_totext(soa_fieldnames[i], target));
index 06de11db54da6fcba4552a675e56cfb6fb22adb1..2a54785522d8f6202a89fd3f0db56404f1c2f382 100644 (file)
@@ -69,7 +69,7 @@ totext_sshfp(ARGS_TOTEXT) {
         */
        n = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u ", n);
+       snprintf(buf, sizeof(buf), "%u ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -77,7 +77,7 @@ totext_sshfp(ARGS_TOTEXT) {
         */
        n = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u", n);
+       snprintf(buf, sizeof(buf), "%u", n);
        RETERR(str_totext(buf, target));
 
        /*
index cbe9b2a66620dfc3fee6c4257882af32b45fddb4..7510aaf3cc0da4d9e2b0443989dd2df155a38e39 100644 (file)
@@ -145,7 +145,7 @@ totext_tkey(ARGS_TOTEXT) {
         */
        n = uint32_fromregion(&sr);
        isc_region_consume(&sr, 4);
-       sprintf(buf, "%lu ", n);
+       snprintf(buf, sizeof(buf), "%lu ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -153,7 +153,7 @@ totext_tkey(ARGS_TOTEXT) {
         */
        n = uint32_fromregion(&sr);
        isc_region_consume(&sr, 4);
-       sprintf(buf, "%lu ", n);
+       snprintf(buf, sizeof(buf), "%lu ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -161,7 +161,7 @@ totext_tkey(ARGS_TOTEXT) {
         */
        n = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%lu ", n);
+       snprintf(buf, sizeof(buf), "%lu ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -172,7 +172,7 @@ totext_tkey(ARGS_TOTEXT) {
        if (dns_tsigrcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS)
                RETERR(str_totext(" ", target));
        else {
-               sprintf(buf, "%lu ", n);
+               snprintf(buf, sizeof(buf), "%lu ", n);
                RETERR(str_totext(buf, target));
        }
 
@@ -181,7 +181,7 @@ totext_tkey(ARGS_TOTEXT) {
         */
        n = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%lu", n);
+       snprintf(buf, sizeof(buf), "%lu", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -209,7 +209,7 @@ totext_tkey(ARGS_TOTEXT) {
         */
        n = uint16_fromregion(&sr);
        isc_region_consume(&sr, 2);
-       sprintf(buf, "%lu", n);
+       snprintf(buf, sizeof(buf), "%lu", n);
        RETERR(str_totext(buf, target));
 
        /*
index e2d9fa0f06844a67f8875df8223186a6d78fc764..a9e80ffbac2547f5a52f6baf9c2a774641c61bfb 100644 (file)
@@ -73,7 +73,7 @@ generic_totext_tlsa(ARGS_TOTEXT) {
         */
        n = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u ", n);
+       snprintf(buf, sizeof(buf), "%u ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -81,7 +81,7 @@ generic_totext_tlsa(ARGS_TOTEXT) {
         */
        n = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u ", n);
+       snprintf(buf, sizeof(buf), "%u ", n);
        RETERR(str_totext(buf, target));
 
        /*
@@ -89,7 +89,7 @@ generic_totext_tlsa(ARGS_TOTEXT) {
         */
        n = uint8_fromregion(&sr);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u", n);
+       snprintf(buf, sizeof(buf), "%u", n);
        RETERR(str_totext(buf, target));
 
        /*
index 9443c2a590770d518646c89809424d8946cccae7..6d706f41dbb72ecada90046ca92210b1f443af67 100644 (file)
@@ -72,7 +72,7 @@ totext_uri(ARGS_TOTEXT) {
         */
        priority = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u ", priority);
+       snprintf(buf, sizeof(buf), "%u ", priority);
        RETERR(str_totext(buf, target));
 
        /*
@@ -80,7 +80,7 @@ totext_uri(ARGS_TOTEXT) {
         */
        weight = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u ", weight);
+       snprintf(buf, sizeof(buf), "%u ", weight);
        RETERR(str_totext(buf, target));
 
        /*
index b1902d722ceeafcab64562d26f5cc2d7201a490e..5b05e0c9965b2bc1e7c4d987e4db71abfe27f821 100644 (file)
@@ -107,7 +107,7 @@ totext_in_a6(ARGS_TOTEXT) {
        prefixlen = sr.base[0];
        INSIST(prefixlen <= 128);
        isc_region_consume(&sr, 1);
-       sprintf(buf, "%u", prefixlen);
+       snprintf(buf, sizeof(buf), "%u", prefixlen);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
 
index 19fb0b101fdf08e23aac4751aafbd5dd54adaa5e..f10b6da4c1aab56a8edfeff08009525456ef7d29 100644 (file)
@@ -65,7 +65,7 @@ totext_in_kx(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
 
        RETERR(str_totext(" ", target));
index 36db1c3e0371995969dda706a3371cf94bbf7fb7..364ee81531a12ec3b83fea52753eb2f5d9e75dfa 100644 (file)
@@ -80,7 +80,7 @@ totext_in_nsap(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        RETERR(str_totext("0x", target));
        while (region.length != 0) {
-               sprintf(buf, "%02x", region.base[0]);
+               snprintf(buf, sizeof(buf), "%02x", region.base[0]);
                isc_region_consume(&region, 1);
                RETERR(str_totext(buf, target));
        }
index 2e9a8ea198ccc88427f082830ee4bd58a428e2c5..5f1da7c2f520054d9bec0ecf85e916f2dd94eb07 100644 (file)
@@ -84,7 +84,7 @@ totext_in_px(ARGS_TOTEXT) {
        dns_rdata_toregion(rdata, &region);
        num = uint16_fromregion(&region);
        isc_region_consume(&region, 2);
-       sprintf(buf, "%u", num);
+       snprintf(buf, sizeof(buf), "%u", num);
        RETERR(str_totext(buf, target));
        RETERR(str_totext(" ", target));
 
index 5141c9f89ac4f7106e4d2105b611a4b87f68c0f6..5f10e6d34e8f2e312a50e92dca921f028ad44e01 100644 (file)
@@ -199,7 +199,7 @@ totext_in_wks(ARGS_TOTEXT) {
        isc_region_consume(&sr, 4);
 
        proto = uint8_fromregion(&sr);
-       sprintf(buf, "%u", proto);
+       snprintf(buf, sizeof(buf), "%u", proto);
        RETERR(str_totext(" ", target));
        RETERR(str_totext(buf, target));
        isc_region_consume(&sr, 1);
@@ -209,7 +209,8 @@ totext_in_wks(ARGS_TOTEXT) {
                if (sr.base[i] != 0)
                        for (j = 0; j < 8; j++)
                                if ((sr.base[i] & (0x80 >> j)) != 0) {
-                                       sprintf(buf, "%u", i * 8 + j);
+                                       snprintf(buf, sizeof(buf),
+                                                "%u", i * 8 + j);
                                        RETERR(str_totext(" ", target));
                                        RETERR(str_totext(buf, target));
                                }
index b82d41613fc569bceafd333f17b375799717e938..224d5c9a98b91c250f9edc6cb8b09a222ccf7be1 100644 (file)
@@ -1046,8 +1046,10 @@ isc_httpd_response(isc_httpd_t *httpd) {
                        return (result);
        }
 
-       sprintf(isc_buffer_used(&httpd->headerbuffer), "%s %03u %s\r\n",
-               httpd->protocol, httpd->retcode, httpd->retmsg);
+       snprintf(isc_buffer_used(&httpd->headerbuffer),
+                (int)isc_buffer_availablelength(&httpd->headerbuffer),
+                "%s %03u %s\r\n", httpd->protocol, httpd->retcode,
+                httpd->retmsg);
        isc_buffer_add(&httpd->headerbuffer, needlen);
 
        return (ISC_R_SUCCESS);
@@ -1072,11 +1074,13 @@ isc_httpd_addheader(isc_httpd_t *httpd, const char *name,
        }
 
        if (val != NULL)
-               sprintf(isc_buffer_used(&httpd->headerbuffer),
-                       "%s: %s\r\n", name, val);
+               snprintf(isc_buffer_used(&httpd->headerbuffer),
+                        isc_buffer_availablelength(&httpd->headerbuffer),
+                        "%s: %s\r\n", name, val);
        else
-               sprintf(isc_buffer_used(&httpd->headerbuffer),
-                       "%s\r\n", name);
+               snprintf(isc_buffer_used(&httpd->headerbuffer),
+                        isc_buffer_availablelength(&httpd->headerbuffer),
+                        "%s\r\n", name);
 
        isc_buffer_add(&httpd->headerbuffer, needlen);
 
@@ -1093,7 +1097,8 @@ isc_httpd_endheaders(isc_httpd_t *httpd) {
                        return (result);
        }
 
-       sprintf(isc_buffer_used(&httpd->headerbuffer), "\r\n");
+       snprintf(isc_buffer_used(&httpd->headerbuffer),
+                isc_buffer_availablelength(&httpd->headerbuffer), "\r\n");
        isc_buffer_add(&httpd->headerbuffer, 2);
 
        return (ISC_R_SUCCESS);
@@ -1105,7 +1110,7 @@ isc_httpd_addheaderuint(isc_httpd_t *httpd, const char *name, int val) {
        unsigned int needlen;
        char buf[sizeof "18446744073709551616"];
 
-       sprintf(buf, "%d", val);
+       snprintf(buf, sizeof(buf), "%d", val);
 
        needlen = strlen(name); /* name itself */
        needlen += 2 + strlen(buf); /* :<space> and val */
@@ -1117,8 +1122,9 @@ isc_httpd_addheaderuint(isc_httpd_t *httpd, const char *name, int val) {
                        return (result);
        }
 
-       sprintf(isc_buffer_used(&httpd->headerbuffer),
-               "%s: %s\r\n", name, buf);
+       snprintf(isc_buffer_used(&httpd->headerbuffer),
+                isc_buffer_availablelength(&httpd->headerbuffer),
+                "%s: %s\r\n", name, buf);
 
        isc_buffer_add(&httpd->headerbuffer, needlen);
 
index 50ee21bcba4ad8e678ac68d35af5923f62635f7a..64ad577e0b7bd1f358282322f4fa810ac2811623 100644 (file)
@@ -81,9 +81,11 @@ inet_ntop4(const unsigned char *src, char *dst, size_t size)
 {
        static const char *fmt = "%u.%u.%u.%u";
        char tmp[sizeof("255.255.255.255")];
+       int n;
 
-       if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size)
-       {
+
+       n = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
+       if (n < 0 || (size_t)n >= size) {
                errno = ENOSPC;
                return (NULL);
        }
@@ -170,7 +172,8 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
                        tp += strlen(tp);
                        break;
                }
-               tp += sprintf(tp, "%x", words[i]);
+               INSIST((tp - tmp) < sizeof(tmp));
+               tp += snprintf(tp, sizeof(tmp) - (tp - tmp), "%x", words[i]);
        }
        /* Was it a trailing run of 0x00's? */
        if (best.base != -1 && (best.base + best.len) ==
index 0f0363c4ce02e2a5a6a39e8e0e91f6c89958469e..9aca630cc15519589eaad72a636c8bd17d825fdb 100644 (file)
@@ -1738,6 +1738,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
                                isc_logmessage_t *message, *next;
                                isc_time_t oldest;
                                isc_interval_t interval;
+                               size_t size;
 
                                isc_interval_set(&interval,
                                                 lcfg->duplicate_interval, 0);
@@ -1811,16 +1812,18 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
                                 * It wasn't in the duplicate interval,
                                 * so add it to the message list.
                                 */
-                               message = isc_mem_get(lctx->mctx,
-                                                   sizeof(isc_logmessage_t) +
-                                                   strlen(lctx->buffer) + 1);
+                               size = sizeof(isc_logmessage_t) +
+                                      strlen(lctx->buffer) + 1;
+                               message = isc_mem_get(lctx->mctx, size);
                                if (message != NULL) {
                                        /*
                                         * Put the text immediately after
                                         * the struct.  The strcpy is safe.
                                         */
                                        message->text = (char *)(message + 1);
-                                       strcpy(message->text, lctx->buffer);
+                                       size -= sizeof(isc_logmessage_t);
+                                       strlcpy(message->text, lctx->buffer,
+                                               size);
 
                                        TIME_NOW(&message->time);
 
index 9d421b86c565e2fd659e55d872997d1f0dea7a12..901545d552cf6aa25240774484d3609f7c87530d 100644 (file)
@@ -2593,7 +2593,7 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) {
        ctxobj = json_object_new_object();
        CHECKMEM(ctxobj);
 
-       sprintf(buf, "%p", ctx);
+       snprintf(buf, sizeof(buf), "%p", ctx);
        obj = json_object_new_string(buf);
        CHECKMEM(obj);
        json_object_object_add(ctxobj, "id", obj);
index 7d2857f22805813eb8f2ed554333967a66d47539..e534d732edd646d68a25c547825d72152bc5199f 100644 (file)
@@ -1983,7 +1983,7 @@ isc_taskmgr_renderjson(isc_taskmgr_t *mgr0, json_object *tasks) {
                CHECKMEM(taskobj);
                json_object_array_add(array, taskobj);
 
-               sprintf(buf, "%p", task);
+               snprintf(buf, sizeof(buf), "%p", task);
                obj = json_object_new_string(buf);
                CHECKMEM(obj);
                json_object_object_add(taskobj, "id", obj);
index 5b32bcc9bc89458d28f80ca82a55aa845cb6f71a..78c91858b3d8efe720b23af2dafe698fef5f8fe2 100644 (file)
@@ -402,7 +402,8 @@ internal_current_clusteralias(isc_interfaceiter_t *iter) {
        memset(&iter->current, 0, sizeof(iter->current));
        iter->current.af = iter->clua_sa.sa_family;
        memset(iter->current.name, 0, sizeof(iter->current.name));
-       sprintf(iter->current.name, "clua%d", ci.aliasid);
+       snprintf(iter->current.name, sizeof(iter->current.name),
+                "clua%d", ci.aliasid);
        iter->current.flags = INTERFACE_F_UP;
        get_inaddr(&iter->current.address, &ci.addr);
        get_inaddr(&iter->current.netmask, &ci.netmask);
index 4299c20d0a845177777f1d91a4f9df6217035045..5062c3858421ca71b97af98767c2408e6f7e5762 100644 (file)
@@ -6766,7 +6766,7 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr0, json_object *stats) {
 
                LOCK(&sock->lock);
 
-               sprintf(buf, "%p", sock);
+               snprintf(buf, sizeof(buf), "%p", sock);
                obj = json_object_new_string(buf);
                CHECKMEM(obj);
                json_object_object_add(entry, "id", obj);
index bbdc6c13039a69e81a2671a9c2d97e0aeaa2c903..456873d5f7c3d537d92c90071bb008d40abff151 100644 (file)
@@ -4151,7 +4151,7 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr, json_object *stats) {
 
                LOCK(&sock->lock);
 
-               sprintf(buf, "%p", sock);
+               snprintf(buf, sizeof(buf), "%p", sock);
                obj = json_object_new_string(buf);
                CHECKMEM(obj);
                json_object_object_add(entry, "id", obj);
index 1eb407f77b6d45a62da3ffde706d6dc7fb0d275b..1871046cd30575de279c6a19435d2d906dcaa1ae 100644 (file)
@@ -2913,8 +2913,8 @@ parser_complain(cfg_parser_t *pctx, isc_boolean_t is_warning,
        len = vsnprintf(message, sizeof(message), format, args);
 #define ELIPSIS " ... "
        if (len >= sizeof(message)) {
-               strcpy(message + sizeof(message) - sizeof(ELIPSIS) - 1,
-                      ELIPSIS);
+               message[sizeof(message) - sizeof(ELIPSIS)] = 0;
+               strlcat(message, ELIPSIS, sizeof(message));
        }
 
        if ((flags & (CFG_LOG_NEAR|CFG_LOG_BEFORE|CFG_LOG_NOPREP)) != 0) {