From: Ondřej Surý Date: Wed, 9 May 2018 12:08:53 +0000 (+0200) Subject: Address GCC 8 -Wstringop-truncation warning X-Git-Tag: v9.13.0~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9845c4c4a7c4b5a12b2cd7ed36d403bb89542cc4;p=thirdparty%2Fbind9.git Address GCC 8 -Wstringop-truncation warning --- diff --git a/bin/tests/system/dlzexternal/driver.c b/bin/tests/system/dlzexternal/driver.c index 8821b0ac0f5..a0730f37c74 100644 --- a/bin/tests/system/dlzexternal/driver.c +++ b/bin/tests/system/dlzexternal/driver.c @@ -397,31 +397,42 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, isc_sockaddr_t *src; char full_name[256]; char buf[512]; - static char last[256] = { 0 }; + static char last[256]; static int count = 0; - int i; + int i, size; UNUSED(zone); - if (state->putrr == NULL) + if (state->putrr == NULL) { return (ISC_R_NOTIMPLEMENTED); + } if (strcmp(name, "@") == 0) { - strncpy(full_name, state->zone_name, 255); - full_name[255] = '\0'; - } else if (strcmp(state->zone_name, ".") == 0) - snprintf(full_name, 255, "%s.", name); - else - snprintf(full_name, 255, "%s.%s", name, state->zone_name); + size = snprintf(full_name, sizeof(full_name), + "%s", state->zone_name); + } else if (strcmp(state->zone_name, ".") == 0) { + size = snprintf(full_name, sizeof(full_name), + "%s.", name); + } else { + size = snprintf(full_name, sizeof(full_name), + "%s.%s", name, state->zone_name); + } + + if (size < 0 || + (size_t)size >= sizeof(full_name) || + (size_t)size >= sizeof(last)) + { + return (ISC_R_NOSPACE); + } /* * For test purposes, log all calls to dlz_lookup() */ - if (strncasecmp(full_name, last, 255) == 0) + if (strcasecmp(full_name, last) == 0) { count++; - else { + } else { count = 1; - strncpy(last, full_name, 255); + memcpy(last, full_name, size + 1); } state->log(ISC_LOG_INFO, "lookup #%d for %s", count, full_name); @@ -450,7 +461,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, } if (strcmp(name, "source-addr") == 0) { - strcpy(buf, "unknown"); + strncpy(buf, "unknown", sizeof(buf)); if (methods != NULL && methods->sourceip != NULL && (methods->version - methods->age <=