From: Ondřej Surý Date: Wed, 21 Mar 2018 16:38:29 +0000 (+0000) Subject: Remove isc_string_printf and isc_string_printf_truncate. X-Git-Tag: v9.13.0~60^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9fda5253fdd86d30a85a61b21bb72d8299145842;p=thirdparty%2Fbind9.git Remove isc_string_printf and isc_string_printf_truncate. Replace with simple snprintf() as appropriate. --- diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index e753f74c992..2c671edd400 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -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; diff --git a/lib/dns/journal.c b/lib/dns/journal.c index 09f665e6c8b..d89ea4db1c3 100644 --- a/lib/dns/journal.c +++ b/lib/dns/journal.c @@ -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) { diff --git a/lib/dns/ssu.c b/lib/dns/ssu.c index 3f9cd74961a..9ceb4fba908 100644 --- a/lib/dns/ssu.c +++ b/lib/dns/ssu.c @@ -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); diff --git a/lib/isc/include/isc/string.h b/lib/isc/include/isc/string.h index 16987ef750f..eb9376039a7 100644 --- a/lib/isc/include/isc/string.h +++ b/lib/isc/include/isc/string.h @@ -32,50 +32,6 @@ 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); /* diff --git a/lib/isc/string.c b/lib/isc/string.c index 5701f1471e3..ddd9c8ca3f4 100644 --- a/lib/isc/string.c +++ b/lib/isc/string.c @@ -50,42 +50,6 @@ #include #include -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; diff --git a/lib/isc/win32/libisc.def.in b/lib/isc/win32/libisc.def.in index ee08d90b428..d7dc4101e08 100644 --- a/lib/isc/win32/libisc.def.in +++ b/lib/isc/win32/libisc.def.in @@ -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