]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove isc_string_printf and isc_string_printf_truncate.
authorOndřej Surý <ondrej@sury.org>
Wed, 21 Mar 2018 16:38:29 +0000 (16:38 +0000)
committerOndřej Surý <ondrej@sury.org>
Thu, 12 Apr 2018 08:37:33 +0000 (10:37 +0200)
Replace with simple snprintf() as appropriate.

bin/nsupdate/nsupdate.c
lib/dns/journal.c
lib/dns/ssu.c
lib/isc/include/isc/string.h
lib/isc/string.c
lib/isc/win32/libisc.def.in

index e753f74c992a0c54e2087a8c4abeabdf4753529a..2c671edd4009c43b0efddc600ab1f0ce7217bdd8 100644 (file)
@@ -2910,33 +2910,31 @@ start_gssrequest(dns_name_t *master) {
        if (realm == NULL)
                get_ticket_realm(gmctx);
 
-       result = isc_string_printf(servicename, sizeof(servicename),
-                                  "DNS/%s%s", namestr, realm ? realm : "");
-       if (result != ISC_R_SUCCESS)
-               fatal("isc_string_printf(servicename) failed: %s",
-                     isc_result_totext(result));
+       result = snprintf(servicename, sizeof(servicename), "DNS/%s%s", namestr, realm ? realm : "");
+       RUNTIME_CHECK(result < sizeof(servicename));
        isc_buffer_init(&buf, servicename, strlen(servicename));
        isc_buffer_add(&buf, strlen(servicename));
        result = dns_name_fromtext(servname, &buf, dns_rootname, 0, NULL);
-       if (result != ISC_R_SUCCESS)
+       if (result != ISC_R_SUCCESS) {
                fatal("dns_name_fromtext(servname) failed: %s",
                      isc_result_totext(result));
+       }
 
        keyname = dns_fixedname_initname(&fkname);
 
        isc_random_get(&val);
-       result = isc_string_printf(mykeystr, sizeof(mykeystr), "%u.sig-%s",
-                                  val, namestr);
-       if (result != ISC_R_SUCCESS)
-               fatal("isc_string_printf(mykeystr) failed: %s",
-                     isc_result_totext(result));
+
+       result = snprintf(mykeystr, sizeof(mykeystr), "%u.sig-%s", val, namestr);
+       RUNTIME_CHECK(result <= sizeof(mykeystr));
+
        isc_buffer_init(&buf, mykeystr, strlen(mykeystr));
        isc_buffer_add(&buf, strlen(mykeystr));
 
        result = dns_name_fromtext(keyname, &buf, dns_rootname, 0, NULL);
-       if (result != ISC_R_SUCCESS)
+       if (result != ISC_R_SUCCESS) {
                fatal("dns_name_fromtext(keyname) failed: %s",
                      isc_result_totext(result));
+       }
 
        /* Windows doesn't recognize name compression in the key name. */
        keyname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
index 09f665e6c8b27f2d49476986db39dcbd7dad7a9c..d89ea4db1c3b8b0262dfb27a3751429005d78a7b 100644 (file)
@@ -705,10 +705,11 @@ dns_journal_open(isc_mem_t *mctx, const char *filename, unsigned int mode,
                if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0)
                        namelen -= 4;
 
-               result = isc_string_printf(backup, sizeof(backup), "%.*s.jbk",
-                                          (int)namelen, filename);
-               if (result != ISC_R_SUCCESS)
-                       return (result);
+               result = snprintf(backup, sizeof(backup), "%.*s.jbk",
+                                 (int)namelen, filename);
+               if (result >= sizeof(backup)) {
+                       return ISC_R_NOSPACE;
+               }
                result = journal_open(mctx, backup, writable, writable,
                                      journalp);
        }
@@ -2100,25 +2101,24 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
        unsigned int size = 0;
        isc_result_t result;
        unsigned int indexend;
-       char newname[1024];
-       char backup[1024];
+       char newname[PATH_MAX];
+       char backup[PATH_MAX];
        isc_boolean_t is_backup = ISC_FALSE;
 
        REQUIRE(filename != NULL);
 
        namelen = strlen(filename);
-       if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0)
+       if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0) {
                namelen -= 4;
+       }
 
-       result = isc_string_printf(newname, sizeof(newname), "%.*s.jnw",
-                                  (int)namelen, filename);
-       if (result != ISC_R_SUCCESS)
-               return (result);
+       result = snprintf(newname, sizeof(newname), "%.*s.jnw",
+                         (int)namelen, filename);
+       RUNTIME_CHECK(result < sizeof(newname));
 
-       result = isc_string_printf(backup, sizeof(backup), "%.*s.jbk",
-                                  (int)namelen, filename);
-       if (result != ISC_R_SUCCESS)
-               return (result);
+       result = snprintf(backup, sizeof(backup), "%.*s.jbk",
+                         (int)namelen, filename);
+       RUNTIME_CHECK(result < sizeof(backup));
 
        result = journal_open(mctx, filename, ISC_FALSE, ISC_FALSE, &j1);
        if (result == ISC_R_NOTFOUND) {
index 3f9cd74961a45b0d04d7237bef4a90ca80055571..9ceb4fba9089b26775c06d36a327ffd8fb9541a5 100644 (file)
@@ -258,37 +258,37 @@ reverse_from_address(dns_name_t *tcpself, const isc_netaddr_t *tcpaddr) {
        switch (tcpaddr->family) {
        case AF_INET:
                l = ntohl(tcpaddr->type.in.s_addr);
-               result = isc_string_printf(buf, sizeof(buf),
-                                          "%lu.%lu.%lu.%lu.IN-ADDR.ARPA.",
-                                          (l >> 0) & 0xff, (l >> 8) & 0xff,
-                                          (l >> 16) & 0xff, (l >> 24) & 0xff);
-               RUNTIME_CHECK(result == ISC_R_SUCCESS);
+               result = snprintf(buf, sizeof(buf),
+                                 "%lu.%lu.%lu.%lu.IN-ADDR.ARPA.",
+                                 (l >> 0) & 0xff, (l >> 8) & 0xff,
+                                 (l >> 16) & 0xff, (l >> 24) & 0xff);
+               RUNTIME_CHECK(result < sizeof(buf));
                break;
        case AF_INET6:
                ap = tcpaddr->type.in6.s6_addr;
-               result = isc_string_printf(buf, sizeof(buf),
-                                          "%x.%x.%x.%x.%x.%x.%x.%x."
-                                          "%x.%x.%x.%x.%x.%x.%x.%x."
-                                          "%x.%x.%x.%x.%x.%x.%x.%x."
-                                          "%x.%x.%x.%x.%x.%x.%x.%x."
-                                          "IP6.ARPA.",
-                                          ap[15] & 0x0f, (ap[15] >> 4) & 0x0f,
-                                          ap[14] & 0x0f, (ap[14] >> 4) & 0x0f,
-                                          ap[13] & 0x0f, (ap[13] >> 4) & 0x0f,
-                                          ap[12] & 0x0f, (ap[12] >> 4) & 0x0f,
-                                          ap[11] & 0x0f, (ap[11] >> 4) & 0x0f,
-                                          ap[10] & 0x0f, (ap[10] >> 4) & 0x0f,
-                                          ap[9] & 0x0f, (ap[9] >> 4) & 0x0f,
-                                          ap[8] & 0x0f, (ap[8] >> 4) & 0x0f,
-                                          ap[7] & 0x0f, (ap[7] >> 4) & 0x0f,
-                                          ap[6] & 0x0f, (ap[6] >> 4) & 0x0f,
-                                          ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
-                                          ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
-                                          ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
-                                          ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
-                                          ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
-                                          ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
-               RUNTIME_CHECK(result == ISC_R_SUCCESS);
+               result = snprintf(buf, sizeof(buf),
+                                 "%x.%x.%x.%x.%x.%x.%x.%x."
+                                 "%x.%x.%x.%x.%x.%x.%x.%x."
+                                 "%x.%x.%x.%x.%x.%x.%x.%x."
+                                 "%x.%x.%x.%x.%x.%x.%x.%x."
+                                 "IP6.ARPA.",
+                                 ap[15] & 0x0f, (ap[15] >> 4) & 0x0f,
+                                 ap[14] & 0x0f, (ap[14] >> 4) & 0x0f,
+                                 ap[13] & 0x0f, (ap[13] >> 4) & 0x0f,
+                                 ap[12] & 0x0f, (ap[12] >> 4) & 0x0f,
+                                 ap[11] & 0x0f, (ap[11] >> 4) & 0x0f,
+                                 ap[10] & 0x0f, (ap[10] >> 4) & 0x0f,
+                                 ap[9] & 0x0f, (ap[9] >> 4) & 0x0f,
+                                 ap[8] & 0x0f, (ap[8] >> 4) & 0x0f,
+                                 ap[7] & 0x0f, (ap[7] >> 4) & 0x0f,
+                                 ap[6] & 0x0f, (ap[6] >> 4) & 0x0f,
+                                 ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
+                                 ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
+                                 ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
+                                 ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
+                                 ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
+                                 ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
+               RUNTIME_CHECK(result < sizeof(buf));
                break;
        default:
                INSIST(0);
@@ -310,27 +310,27 @@ stf_from_address(dns_name_t *stfself, const isc_netaddr_t *tcpaddr) {
        switch(tcpaddr->family) {
        case AF_INET:
                l = ntohl(tcpaddr->type.in.s_addr);
-               result = isc_string_printf(buf, sizeof(buf),
-                                          "%lx.%lx.%lx.%lx.%lx.%lx.%lx.%lx"
-                                          "2.0.0.2.IP6.ARPA.",
-                                          l & 0xf, (l >> 4) & 0xf,
-                                          (l >> 8) & 0xf, (l >> 12) & 0xf,
-                                          (l >> 16) & 0xf, (l >> 20) & 0xf,
-                                          (l >> 24) & 0xf, (l >> 28) & 0xf);
-               RUNTIME_CHECK(result == ISC_R_SUCCESS);
+               result = snprintf(buf, sizeof(buf),
+                                 "%lx.%lx.%lx.%lx.%lx.%lx.%lx.%lx"
+                                 "2.0.0.2.IP6.ARPA.",
+                                 l & 0xf, (l >> 4) & 0xf,
+                                 (l >> 8) & 0xf, (l >> 12) & 0xf,
+                                 (l >> 16) & 0xf, (l >> 20) & 0xf,
+                                 (l >> 24) & 0xf, (l >> 28) & 0xf);
+               RUNTIME_CHECK(result < sizeof(buf));
                break;
        case AF_INET6:
                ap = tcpaddr->type.in6.s6_addr;
-               result = isc_string_printf(buf, sizeof(buf),
-                                          "%x.%x.%x.%x.%x.%x.%x.%x."
-                                          "%x.%x.%x.%x.IP6.ARPA.",
-                                          ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
-                                          ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
-                                          ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
-                                          ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
-                                          ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
-                                          ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
-               RUNTIME_CHECK(result == ISC_R_SUCCESS);
+               result = snprintf(buf, sizeof(buf),
+                                 "%x.%x.%x.%x.%x.%x.%x.%x."
+                                 "%x.%x.%x.%x.IP6.ARPA.",
+                                 ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
+                                 ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
+                                 ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
+                                 ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
+                                 ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
+                                 ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
+               RUNTIME_CHECK(result < sizeof(buf));
                break;
        default:
                INSIST(0);
index 16987ef750faab820c0f6774720244a475f336d9..eb9376039a7e6f8549fa51a13903d4f5e9b0997d 100644 (file)
 
 ISC_LANG_BEGINDECLS
 
-isc_result_t
-isc_string_printf(char *target, size_t size, const char *format, ...)
-       ISC_FORMAT_PRINTF(3, 4);
-/*
- * Print 'format' to 'target' which is a pointer to a string of at least
- * 'size' bytes.
- *
- * Requires:
- *     'target' is a pointer to a char[] of at least 'size' bytes.
- *     'size' an integer > 0.
- *     'format' == NULL or points to a NUL terminated string.
- *
- * Ensures:
- *     If result == ISC_R_SUCCESS
- *             'target' will be a NUL terminated string of no more
- *             than 'size' bytes (including NUL).
- *
- *     If result == ISC_R_NOSPACE
- *             'target' is undefined.
- *
- * Returns:
- *     ISC_R_SUCCESS  -- 'format' was successfully printed to 'target'.
- *     ISC_R_NOSPACE  -- 'format' could not be printed to 'target' since it
- *                       is too small.
- */
-
-void
-isc_string_printf_truncate(char *target, size_t size, const char *format, ...)
-       ISC_FORMAT_PRINTF(3, 4);
-/*
- * Print 'format' to 'target' which is a pointer to a string of at least
- * 'size' bytes.
- *
- * Requires:
- *     'target' is a pointer to a char[] of at least 'size' bytes.
- *     'size' an integer > 0.
- *     'format' == NULL or points to a NUL terminated string.
- *
- * Ensures:
- *     'target' will be a NUL terminated string of no more
- *     than 'size' bytes (including NUL).
- */
-
-
 char *
 isc_string_regiondup(isc_mem_t *mctx, const isc_region_t *source);
 /*
index 5701f1471e345da22e6cc6e909ed4a20fd295777..ddd9c8ca3f4373853eb0744aeade068287b8a450 100644 (file)
 #include <isc/string.h>
 #include <isc/util.h>
 
-isc_result_t
-isc_string_printf(char *target, size_t size, const char *format, ...) {
-       va_list args;
-       size_t n;
-
-       REQUIRE(size > 0U);
-
-       va_start(args, format);
-       n = vsnprintf(target, size, format, args);
-       va_end(args);
-
-       if (n >= size) {
-               memset(target, ISC_STRING_MAGIC, size);
-               return (ISC_R_NOSPACE);
-       }
-
-       ENSURE(strlen(target) < size);
-
-       return (ISC_R_SUCCESS);
-}
-
-void
-isc_string_printf_truncate(char *target, size_t size, const char *format, ...)
-{
-       va_list args;
-
-       REQUIRE(size > 0U);
-
-       va_start(args, format);
-       /* check return code? */
-       (void)vsnprintf(target, size, format, args);
-       va_end(args);
-
-       ENSURE(strlen(target) < size);
-}
-
 char *
 isc_string_regiondup(isc_mem_t *mctx, const isc_region_t *source) {
        char *target;
index ee08d90b4289fa70e70dba0d02d52e7b03656e26..d7dc4101e080d20abddf4908e0c84d7cac5db50c 100644 (file)
@@ -645,8 +645,6 @@ isc_stdio_sync
 isc_stdio_tell
 isc_stdio_write
 isc_stdtime_get
-isc_string_printf
-isc_string_printf_truncate
 isc_string_regiondup
 isc_string_separate
 isc_string_strcasestr