From: Ondřej Surý Date: Wed, 21 Mar 2018 16:20:59 +0000 (+0000) Subject: Remove isc_string_copy, isc_string_copy_truncate and isc_string_append. X-Git-Tag: v9.13.0~60^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ccdb0287e8462c0bcb91798b93f592c4ccc6ddcf;p=thirdparty%2Fbind9.git Remove isc_string_copy, isc_string_copy_truncate and isc_string_append. Use strlcpy and strlcat as appropriate instead. --- diff --git a/lib/isc/include/isc/string.h b/lib/isc/include/isc/string.h index 0c77f87b37f..16987ef750f 100644 --- a/lib/isc/include/isc/string.h +++ b/lib/isc/include/isc/string.h @@ -32,73 +32,6 @@ ISC_LANG_BEGINDECLS -isc_result_t -isc_string_copy(char *target, size_t size, const char *source); -/* - * Copy the string pointed to by 'source' 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. - * 'source' == 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 -- 'source' was successfully copied to 'target'. - * ISC_R_NOSPACE -- 'source' could not be copied since 'target' - * is too small. - */ - -void -isc_string_copy_truncate(char *target, size_t size, const char *source); -/* - * Copy the string pointed to by 'source' 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. - * 'source' == NULL or points to a NUL terminated string. - * - * Ensures: - * 'target' will be a NUL terminated string of no more - * than 'size' bytes (including NUL). - */ - -isc_result_t -isc_string_append(char *target, size_t size, const char *source); -/* - * Append the string pointed to by 'source' to 'target' which is a - * pointer to a NUL terminated string of at least 'size' bytes. - * - * Requires: - * 'target' is a pointer to a NUL terminated char[] of at - * least 'size' bytes. - * 'size' an integer > 0. - * 'source' == 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 -- 'source' was successfully appended to 'target'. - * ISC_R_NOSPACE -- 'source' could not be appended since 'target' - * is too small. - */ - isc_result_t isc_string_printf(char *target, size_t size, const char *format, ...) ISC_FORMAT_PRINTF(3, 4); diff --git a/lib/isc/string.c b/lib/isc/string.c index a9e5d40aa64..5701f1471e3 100644 --- a/lib/isc/string.c +++ b/lib/isc/string.c @@ -50,44 +50,6 @@ #include #include -isc_result_t -isc_string_copy(char *target, size_t size, const char *source) { - REQUIRE(size > 0U); - - if (strlcpy(target, source, size) >= size) { - memset(target, ISC_STRING_MAGIC, size); - return (ISC_R_NOSPACE); - } - - ENSURE(strlen(target) < size); - - return (ISC_R_SUCCESS); -} - -void -isc_string_copy_truncate(char *target, size_t size, const char *source) { - REQUIRE(size > 0U); - - strlcpy(target, source, size); - - ENSURE(strlen(target) < size); -} - -isc_result_t -isc_string_append(char *target, size_t size, const char *source) { - REQUIRE(size > 0U); - REQUIRE(strlen(target) < size); - - if (strlcat(target, source, size) >= size) { - memset(target, ISC_STRING_MAGIC, size); - return (ISC_R_NOSPACE); - } - - ENSURE(strlen(target) < size); - - return (ISC_R_SUCCESS); -} - isc_result_t isc_string_printf(char *target, size_t size, const char *format, ...) { va_list args; diff --git a/lib/isc/win32/libisc.def.in b/lib/isc/win32/libisc.def.in index 85beac7e695..ee08d90b428 100644 --- a/lib/isc/win32/libisc.def.in +++ b/lib/isc/win32/libisc.def.in @@ -645,9 +645,6 @@ isc_stdio_sync isc_stdio_tell isc_stdio_write isc_stdtime_get -isc_string_append -isc_string_copy -isc_string_copy_truncate isc_string_printf isc_string_printf_truncate isc_string_regiondup diff --git a/lib/samples/nsprobe.c b/lib/samples/nsprobe.c index 6830c2f6153..46088cd8dc2 100644 --- a/lib/samples/nsprobe.c +++ b/lib/samples/nsprobe.c @@ -467,17 +467,18 @@ set_nextqname(struct probe_trans *trans) { isc_buffer_t b; char buf[4096]; /* XXX ad-hoc constant, but should be enough */ - if (*trans->qlabel == NULL) + if (*trans->qlabel == NULL) { return (ISC_R_NOMORE); + } - result = isc_string_copy(buf, sizeof(buf), *trans->qlabel); - if (result != ISC_R_SUCCESS) - return (result); - result = isc_string_append(buf, sizeof(buf), trans->domain); - if (result != ISC_R_SUCCESS) - return (result); + if (strlcpy(buf, *trans->qlabel, sizeof(buf)) >= sizeof(buf)) { + return ISC_R_NOSPACE; + } - domainlen = strlen(buf); + if ((domainlen = strlcat(buf, trans->domain, sizeof(buf))) >= sizeof(buf)) { + return ISC_R_NOSPACE; + } + isc_buffer_init(&b, buf, domainlen); isc_buffer_add(&b, domainlen); trans->qname = dns_fixedname_initname(&trans->fixedname);