Use strlcpy and strlcat as appropriate instead.
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);
#include <isc/string.h>
#include <isc/util.h>
-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;
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
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);