+4722. [cleanup] Clean up uses of strcpy() and strcat() in favor of
+ strlcpy() and strlcat() for safety. [RT #45981]
+
4721. [func] 'dnssec-signzone -x' and 'dnssec-dnskey-kskonly'
options now apply to CDNSKEY and DS records as well
as DNSKEY. Thanks to Tony Finch. [RT #45689]
/*
* Turn off search.
*/
- if (dns_name_countlabels(name) > 1U)
- strcat(namebuf, ".");
+ if (dns_name_countlabels(name) > 1U) {
+ strlcat(namebuf, ".", sizeof(namebuf));
+ }
dns_name_format(owner, ownerbuf, sizeof(ownerbuf));
result = getaddrinfo(namebuf, NULL, &hints, &ai);
/*
* Turn off search.
*/
- if (dns_name_countlabels(name) > 1U)
- strcat(namebuf, ".");
+ if (dns_name_countlabels(name) > 1U) {
+ strlcat(namebuf, ".", sizeof(namebuf));
+ }
dns_name_format(owner, ownerbuf, sizeof(ownerbuf));
result = getaddrinfo(namebuf, NULL, &hints, &ai);
/*
* Turn off search.
*/
- if (dns_name_countlabels(name) > 1U)
- strcat(namebuf, ".");
+ if (dns_name_countlabels(name) > 1U) {
+ strlcat(namebuf, ".", sizeof(namebuf));
+ }
dns_name_format(owner, ownerbuf, sizeof(ownerbuf));
result = getaddrinfo(namebuf, NULL, &hints, &ai);
lookup->trace_root = ISC_TF(lookup->trace ||
lookup->ns_search_only);
lookup->new_search = ISC_TRUE;
- strcpy(lookup->textname, ".");
+ strlcpy(lookup->textname, ".", sizeof(lookup->textname));
lookup->rdtype = dns_rdatatype_ns;
lookup->rdtypeset = ISC_TRUE;
if (firstarg) {
namestr, isc_result_totext(lresult));
if (addresses_result == ISC_R_SUCCESS) {
addresses_result = lresult;
- strcpy(bad_namestr, namestr);
+ strlcpy(bad_namestr, namestr,
+ sizeof(bad_namestr));
}
}
numLookups += num;
if (resultp == NULL)
fatal("couldn't get address for '%s': %s",
host, isc_result_totext(result));
- return 0;
+ return (0);
}
for (i = 0; i < count; i++) {
ISC_LIST_APPEND(lookup->my_server_list, srv, link);
}
- return count;
+ return (count);
}
/*%
*/
if (idn_decodename(IDN_DECODE_APP, tmp1, tmp2, MAXDLEN) != idn_success)
return (ISC_R_SUCCESS);
- strcpy(tmp1, tmp2);
+ strlcpy(tmp1, tmp2, MAXDLEN);
/*
* Copy the converted contents in 'tmp1' back to 'buffer'.
/* Already absolute? */
if (namelen > 0 && name[namelen - 1] == '.')
- return idn_success;
+ return (idn_success);
/* Append dot and origin */
if (namelen + 1 + originlen >= namesize)
- return idn_buffer_overflow;
+ return (idn_buffer_overflow);
if (*origin != '.')
name[namelen++] = '.';
- (void)strcpy(name + namelen, origin);
- return idn_success;
+ (void)strlcpy(name + namelen, origin, namesize - namelen);
+ return (idn_success);
}
static void
sprintf(filename, "%s/", dsdir);
else
filename[0] = 0;
- strcat(filename, prefix);
- strcat(filename, namestr);
+ strlcat(filename, prefix, filenamelen);
+ strlcat(filename, namestr, filenamelen);
dns_diff_init(mctx, &diff);
free(memstats);
memstats = NULL;
}
+
if (filename == NULL)
return;
- memstats = malloc(strlen(filename) + 1);
- if (memstats)
- strcpy(memstats, filename);
+
+ memstats = strdup(filename);
}
#ifdef HAVE_LIBSCF
(s6[prefixlen/8] >> 4) & 0xf);
cp += 4;
}
- strcat(cp, "ip6.arpa.");
+
+ strlcat(reverse, "ip6.arpa.", sizeof(reverse));
/*
* Create the actual zone.
*/
strlcpy(tempname, view->new_zone_file, sizeof(tempname));
if (strlen(tempname) < sizeof(tempname) - 1) {
- strcat(tempname, "~");
+ strlcat(tempname, "~", sizeof(tempname));
isc_file_rename(view->new_zone_file, tempname);
}
memset(&uts, 0, sizeof(uts));
if (uname(&uts) < 0) {
- strcpy(unamebuf, "unknown architecture");
+ snprintf(unamebuf, sizeof(unamebuf), "unknown architecture");
return;
}
"%s %s %s %s",
uts.sysname, uts.machine, uts.release, uts.version);
#else
- strcpy(unamebuf, "unknown architecture");
+ snprintf(unamebuf, sizeof(unamebuf), "unknown architecture");
#endif
unamep = unamebuf;
}
RUNTIME_CHECK(dns_dbtable_create(mctx, dns_rdataclass_in, &dbtable) ==
ISC_R_SUCCESS);
-
-
- strcpy(dbtype, "rbt");
+ snprintf(dbtype, sizeof(dbtype), "rbt");
while ((ch = isc_commandline_parse(argc, argv, "c:d:t:z:P:Q:glpqvT"))
!= -1) {
switch (ch) {
print_digest(s, "hmacmd5", digest, 4);
s = "what do ya want for nothing?";
- strcpy((char *)key, "Jefe");
+ strlcpy((char *)key, "Jefe", sizeof(key));
isc_hmacmd5_init(&hmacmd5, key, 4);
memmove(buffer, s, strlen(s));
isc_hmacmd5_update(&hmacmd5, buffer, strlen(s));
print_digest(s, "hmacsha1", digest, ISC_SHA1_DIGESTLENGTH/4);
s = "what do ya want for nothing?";
- strcpy((char *)key, "Jefe");
+ strlcpy((char *)key, "Jefe", sizeof(key));
isc_hmacsha1_init(&hmacsha1, key, 4);
memmove(buffer, s, strlen(s));
isc_hmacsha1_update(&hmacsha1, buffer, strlen(s));
print_digest(s, "hmacsha224", digest, ISC_SHA224_DIGESTLENGTH/4);
s = "what do ya want for nothing?";
- strcpy((char *)key, "Jefe");
+ strlcpy((char *)key, "Jefe", sizeof(key));
isc_hmacsha224_init(&hmacsha224, key, 4);
memmove(buffer, s, strlen(s));
isc_hmacsha224_update(&hmacsha224, buffer, strlen(s));
print_digest(s, "hmacsha256", digest, ISC_SHA256_DIGESTLENGTH/4);
s = "what do ya want for nothing?";
- strcpy((char *)key, "Jefe");
+ strlcpy((char *)key, "Jefe", sizeof(key));
isc_hmacsha256_init(&hmacsha256, key, 4);
memmove(buffer, s, strlen(s));
isc_hmacsha256_update(&hmacsha256, buffer, strlen(s));
print_digest(s, "hmacsha384", digest, ISC_SHA384_DIGESTLENGTH/4);
s = "what do ya want for nothing?";
- strcpy((char *)key, "Jefe");
+ strlcpy((char *)key, "Jefe", sizeof(key));
isc_hmacsha384_init(&hmacsha384, key, 4);
memmove(buffer, s, strlen(s));
isc_hmacsha384_update(&hmacsha384, buffer, strlen(s));
print_digest(s, "hmacsha512", digest, ISC_SHA512_DIGESTLENGTH/4);
s = "what do ya want for nothing?";
- strcpy((char *)key, "Jefe");
+ strlcpy((char *)key, "Jefe", sizeof(key));
isc_hmacsha512_init(&hmacsha512, key, 4);
memmove(buffer, s, strlen(s));
isc_hmacsha512_update(&hmacsha512, buffer, strlen(s));
ti->ticks = 0;
if (name != NULL) {
INSIST(strlen(name) < sizeof(ti->name));
- strcpy(ti->name, name);
- } else
- sprintf(ti->name, "%d", task_count);
+ strlcpy(ti->name, name, sizeof(ti->name));
+ } else {
+ snprintf(ti->name, sizeof(ti->name), "%d", task_count);
+ }
RUNTIME_CHECK(isc_task_create(task_manager, 0, &ti->task) ==
ISC_R_SUCCESS);
RUNTIME_CHECK(isc_task_onshutdown(ti->task, shutdown_action, ti) ==
* Send a GET string, and set up to receive (and just display)
* the result.
*/
- strcpy(buf, "GET / HTTP/1.1\r\nHost: www.flame.org\r\n"
- "Connection: Close\r\n\r\n");
+ snprintf(buf, sizeof(buf),
+ "GET / HTTP/1.1\r\nHost: www.flame.org\r\n"
+ "Connection: Close\r\n\r\n");
region.base = isc_mem_get(mctx, strlen(buf) + 1);
if (region.base != NULL) {
region.length = strlen(buf) + 1;
strcpy((char *)region.base, buf); /* This strcpy is safe. */
- } else
+ } else {
region.length = 0;
+ }
isc_socket_send(sock, ®ion, task, my_http_get, event->ev_arg);
char soa_data[1024];
const char *extra;
isc_result_t result;
+ size_t znsize;
int n;
UNUSED(dlzname);
}
/* Ensure zone name is absolute */
- state->zone_name = malloc(strlen(argv[1]) + 2);
+ znsize = strlen(argv[1]) + 2;
+ state->zone_name = malloc(znsize);
if (state->zone_name == NULL) {
free(state);
return (ISC_R_NOMEMORY);
}
- if (argv[1][strlen(argv[1]) - 1] == '.')
- strcpy(state->zone_name, argv[1]);
- else
- sprintf(state->zone_name, "%s.", argv[1]);
+ if (argv[1][strlen(argv[1]) - 1] == '.') {
+ strlcpy(state->zone_name, argv[1], znsize);
+ } else {
+ snprintf(state->zone_name, znsize, "%s.", argv[1]);
+ }
if (strcmp(state->zone_name, ".") == 0)
extra = ".root";
char addrbuf[100];
char absolute[1024];
- strcpy(addrbuf, "unknown");
+ strlcpy(addrbuf, "unknown", sizeof(addrbuf));
if (methods != NULL &&
methods->sourceip != NULL &&
methods->version - methods->age <= DNS_CLIENTINFOMETHODS_VERSION &&
}
if (strcmp(name, "source-addr") == 0) {
- strcpy(buf, "unknown");
+ strlcpy(buf, "unknown", sizeof(buf));
if (methods != NULL &&
methods->sourceip != NULL &&
(methods->version - methods->age <=
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-/* $Id: getaddresses.c,v 1.22 2007/06/19 23:47:16 tbox Exp $ */
-
/*! \file */
#include <config.h>
#include <isc/netscope.h>
#include <isc/result.h>
#include <isc/sockaddr.h>
+#include <isc/string.h>
#include <isc/util.h>
#include <bind9/getaddresses.h>
char tmpbuf[128], *d;
isc_uint32_t zone = 0;
- strcpy(tmpbuf, hostname);
+ strlcpy(tmpbuf, hostname, sizeof(tmpbuf));
d = strchr(tmpbuf, '%');
if (d != NULL)
*d = '\0';
(bytes[1] & 0xff),
(bytes[0] & 0xff));
} else if (address->family == AF_INET6) {
+ size_t remaining;
+
cp = textname;
for (i = 15; i >= 0; i--) {
*cp++ = hex_digits[bytes[i] & 0x0f];
*cp++ = hex_digits[(bytes[i] >> 4) & 0x0f];
*cp++ = '.';
}
- if ((options & DNS_BYADDROPT_IPV6INT) != 0)
- strcpy(cp, "ip6.int.");
- else
- strcpy(cp, "ip6.arpa.");
+ remaining = sizeof(textname) - (cp - textname);
+ if ((options & DNS_BYADDROPT_IPV6INT) != 0) {
+ strlcpy(cp, "ip6.int.", remaining);
+ } else {
+ strlcpy(cp, "ip6.arpa.", remaining);
+ }
} else
return (ISC_R_NOTIMPLEMENTED);
NULL, /* setcachestats */
NULL, /* hashsize */
NULL, /* nodefullname */
- NULL /* getsize */
+ NULL, /* getsize */
+ NULL, /* setservestalettl */
+ NULL, /* getservestalettl */
};
static dns_rdatasetmethods_t rpsdb_rdataset_methods = {
for (i = 0; i < TYPENAMES; i++)
memset(&typenames[i], 0, sizeof(typenames[i]));
- strcpy(srcdir, "");
+ srcdir[0] = '\0';
while ((c = isc_commandline_parse(argc, argv, "cdits:F:P:S:")) != -1)
switch (c) {
case 'c':
n = snprintf(year, sizeof(year), "-%d",
tm->tm_year + 1900);
INSIST(n > 0 && (unsigned)n < sizeof(year));
- } else
- strcpy(year, "-2016");
- } else
- strcpy(year, "-2016");
+ } else {
+ snprintf(year, sizeof(year), "-2016");
+ }
+ } else {
+ snprintf(year, sizeof(year), "-2016");
+ }
- if (!depend) fprintf(stdout, copyright, year);
+ if (!depend)
+ fprintf(stdout, copyright, year);
if (code) {
fputs("#ifndef DNS_CODE_H\n", stdout);
continue;
}
nibblemode = ISC_FALSE;
- strcpy(fmt, "%d");
+ strlcpy(fmt, "%d", sizeof(fmt));
/* Get format specifier. */
if (*name == '{' ) {
n = sscanf(name, "{%d,%u,%1[doxXnN]}",
} else {
if (trem < 3)
return (ISC_R_NOSPACE);
- sprintf(tdata, "%%%02X", c);
+ snprintf(tdata, trem, "%%%02X", c);
tdata += 3;
trem -= 3;
ndata++;
dns_name_format(&rbtdb->common.origin, buf,
sizeof(buf));
else
- strcpy(buf, "<UNKNOWN>");
+ strlcpy(buf, "<UNKNOWN>", sizeof(buf));
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_CACHE, ISC_LOG_DEBUG(1),
"done free_rbtdb(%s)", buf);
dns_name_format(&rbtdb->common.origin, buf,
sizeof(buf));
} else {
- strcpy(buf, "<UNKNOWN>");
+ strlcpy(buf, "<UNKNOWN>", sizeof(buf));
}
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_CACHE, ISC_LOG_DEBUG(1),
dns_name_format(&rbtdb->common.origin, buf,
sizeof(buf));
else
- strcpy(buf, "<UNKNOWN>");
+ strlcpy(buf, "<UNKNOWN>", sizeof(buf));
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_CACHE, ISC_LOG_DEBUG(1),
"calling free_rbtdb(%s)", buf);
*/
dns_name_format(name, buf, sizeof(buf));
dns_rdatatype_format(type, typebuf, sizeof(typebuf));
- strcat(buf, "/"); /* checked */
- strcat(buf, typebuf); /* checked */
+ strlcat(buf, "/", sizeof(buf));
+ strlcat(buf, typebuf, sizeof(buf));
fctx->info = isc_mem_strdup(mctx, buf);
if (fctx->info == NULL) {
result = ISC_R_NOMEMORY;
isc_netaddr_fromin(&na, &in4);
elt.subtype = subtype;
- strcpy(elt.as_string, string);
+ strlcpy(elt.as_string, string, sizeof(elt.as_string));
return (dns_geoip_match(&na, scope, &geoip, &elt));
}
isc_netaddr_fromin6(&na, &in6);
elt.subtype = subtype;
- strcpy(elt.as_string, string);
+ strlcpy(elt.as_string, string, sizeof(elt.as_string));
return (dns_geoip_match(&na, scope, &geoip, &elt));
}
isc_result_t
tohexstr(unsigned char *d, unsigned int len, char *out) {
-
- out[0]='\0';
char c_ret[] = "AA";
unsigned int j;
- strcat(out, "0x");
+ int size = len * 2 + 1;
+
+ out[0] = '\0';
+ strlcat(out, "0x", size);
for (j = 0; j < len; j++) {
- sprintf(c_ret, "%02X", d[j]);
- strcat(out, c_ret);
+ snprintf(c_ret, sizeof(c_ret), "%02X", d[j]);
+ strlcat(out, c_ret, size);
}
- strcat(out, "\0");
return (ISC_R_SUCCESS);
}
isc_buffer_t source;
isc_buffer_t target;
- strcpy(origin, TEST_ORIGIN);
+ strlcpy(origin, TEST_ORIGIN, sizeof(origin));
len = strlen(origin);
isc_buffer_init(&source, origin, len);
isc_buffer_add(&source, len);
UNUSED(tc);
- strcpy(myorigin, TEST_ORIGIN);
+ strlcpy(myorigin, TEST_ORIGIN, sizeof(myorigin));
len = strlen(myorigin);
isc_buffer_init(&source, myorigin, len);
isc_buffer_add(&source, len);
if (isc_log_wouldlog(dns_lctx, level) == ISC_FALSE)
return;
- if (key != NULL)
+ if (key != NULL) {
dns_name_format(&key->name, namestr, sizeof(namestr));
- else
- strcpy(namestr, "<null>");
+ } else {
+ strlcpy(namestr, "<null>", sizeof(namestr));
+ }
- if (key != NULL && key->generated && key->creator)
+ if (key != NULL && key->generated && key->creator) {
dns_name_format(key->creator, creatorstr, sizeof(creatorstr));
- else
- strcpy(creatorstr, "<null>");
+ } else {
+ strlcpy(creatorstr, "<null>", sizeof(creatorstr));
+ }
va_start(ap, fmt);
vsnprintf(message, sizeof(message), fmt, ap);
va_end(ap);
- if (key != NULL && key->generated)
+ if (key != NULL && key->generated) {
isc_log_write(dns_lctx,
DNS_LOGCATEGORY_DNSSEC, DNS_LOGMODULE_TSIG,
level, "tsig key '%s' (%s): %s",
namestr, creatorstr, message);
- else
+ } else {
isc_log_write(dns_lctx,
DNS_LOGCATEGORY_DNSSEC, DNS_LOGMODULE_TSIG,
level, "tsig key '%s': %s", namestr, message);
+ }
}
static void
result = isc_socket_getsockname(xfr->socket, &sockaddr);
if (result == ISC_R_SUCCESS) {
isc_sockaddr_format(&sockaddr, sourcetext, sizeof(sourcetext));
- } else
- strcpy(sourcetext, "<UNKNOWN>");
+ } else {
+ strlcpy(sourcetext, "<UNKNOWN>", sizeof(sourcetext));
+ }
if (xfr->tsigkey != NULL && xfr->tsigkey->key != NULL) {
dns_name_format(dst_key_name(xfr->tsigkey->key),
tmp2 += (zone->db_argc + 1) * sizeof(char *);
for (i = 0; i < zone->db_argc; i++) {
*tmp++ = tmp2;
- strcpy(tmp2, zone->db_argv[i]);
+ strlcpy(tmp2, zone->db_argv[i], size);
tmp2 += strlen(tmp2) + 1;
}
*tmp = NULL;
journal = isc_mem_allocate(zone->mctx, len);
if (journal == NULL)
return (ISC_R_NOMEMORY);
- strcpy(journal, zone->masterfile);
- strcat(journal, ".jnl");
+ strlcpy(journal, zone->masterfile, len);
+ strlcat(journal, ".jnl", len);
} else {
journal = NULL;
}
}
salt[j] = '\0';
} else
- strcpy(salt, "-");
+ strlcpy(salt, "-", sizeof(salt));
dns_zone_log(zone, ISC_LOG_NOTICE,
"dns_zone_addnsec3chain(hash=%u, iterations=%u, salt=%s)",
nsec3param->hash, nsec3param->iterations,
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-/* $Id$ */
-
/*! \file */
/*
#include <isc/netaddr.h>
#include <isc/print.h>
#include <isc/sockaddr.h>
+#include <isc/string.h>
#include <isc/util.h>
#include <dns/byaddr.h>
snprintf(numserv, sizeof(numserv), "%d", ntohs(port));
if ((strlen(numserv) + 1) > servlen)
ERR(EAI_OVERFLOW);
- strcpy(serv, numserv);
+ strlcpy(serv, numserv, servlen);
} else {
if ((strlen(sp->s_name) + 1) > servlen)
ERR(EAI_OVERFLOW);
- strcpy(serv, sp->s_name);
+ strlcpy(serv, sp->s_name, servlen);
}
#if 0
#endif
if (strlen(numaddr) + 1 > hostlen)
ERR(EAI_OVERFLOW);
- strcpy(host, numaddr);
+ strlcpy(host, numaddr, hostlen);
} else {
isc_netaddr_t netaddr;
dns_fixedname_t ptrfname;
ERR(EAI_SYSTEM);
if ((strlen(numaddr) + 1) > hostlen)
ERR(EAI_OVERFLOW);
- strcpy(host, numaddr);
+ strlcpy(host, numaddr, hostlen);
}
}
result = SUCCESS;
* \brief Given an operating system specific file name "filename"
* referring to a program, return the canonical program name.
*
- *
* Any directory prefix or executable file name extension (if
* used on the OS in case) is stripped. On systems where program
* names are case insensitive, the name is canonicalized to all
errno = ENOSPC;
return (NULL);
}
- strcpy(dst, tmp);
+ strlcpy(dst, tmp, size);
return (dst);
}
errno = ENOSPC;
return (NULL);
}
- strcpy(dst, tmp);
+ strlcpy(dst, tmp, size);
return (dst);
}
#endif /* AF_INET6 */
memset(netaddr, 0, sizeof(*netaddr));
netaddr->family = AF_UNIX;
- strcpy(netaddr->type.un, path);
+ strlcpy(netaddr->type.un, path, sizeof(netaddr->type.un));
netaddr->zone = 0;
return (ISC_R_SUCCESS);
#else
sockaddr->type.sunix.sun_len =
(unsigned char)sizeof(sockaddr->type.sunix);
#endif
- strcpy(sockaddr->type.sunix.sun_path, path);
+ strlcpy(sockaddr->type.sunix.sun_path, path,
+ sizeof(sockaddr->type.sunix.sun_path));
return (ISC_R_SUCCESS);
#else
UNUSED(sockaddr);
isc_result_t
tohexstr(unsigned char *d, unsigned int len, char *out) {
-
- out[0]='\0';
char c_ret[] = "AA";
unsigned int i;
- strcat(out, "0x");
+ int size = len * 2 + 1;
+
+ out[0] = '\0';
+ strlcat(out, "0x", size);
for (i = 0; i < len; i++) {
- sprintf(c_ret, "%02X", d[i]);
- strcat(out, c_ret);
+ snprintf(c_ret, sizeof(c_ret), "%02X", d[i]);
+ strlcat(out, c_ret, size);
}
- strcat(out, "\0");
return (ISC_R_SUCCESS);
}
result = isc_task_create(taskmgr, 0, &task);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
- strcpy(sendbuf, "Hello");
+ snprintf(sendbuf, sizeof(sendbuf), "Hello");
r.base = (void *) sendbuf;
r.length = strlen(sendbuf) + 1;
result = isc_task_create(taskmgr, 0, &task);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
- strcpy(sendbuf, "Hello");
+ snprintf(sendbuf, sizeof(sendbuf), "Hello");
r.base = (void *) sendbuf;
r.length = strlen(sendbuf) + 1;
ATF_CHECK(completion.done);
ATF_CHECK_EQ(completion.result, ISC_R_SUCCESS);
- strcpy(sendbuf, "World");
+ snprintf(sendbuf, sizeof(sendbuf), "World");
r.base = (void *) sendbuf;
r.length = strlen(sendbuf) + 1;
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS, "%s",
isc_result_totext(result));
- strcpy(sendbuf, "Hello");
+ snprintf(sendbuf, sizeof(sendbuf), "Hello");
r.base = (void *) sendbuf;
r.length = strlen(sendbuf) + 1;
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS, "%s",
isc_result_totext(result));
- strcpy(sendbuf, "Hello");
+ snprintf(sendbuf, sizeof(sendbuf), "Hello");
r.base = (void *) sendbuf;
r.length = strlen(sendbuf) + 1;
isc_socket_dscp(s2, 056); /* EF */
- strcpy(sendbuf, "Hello");
+ snprintf(sendbuf, sizeof(sendbuf), "Hello");
r.base = (void *) sendbuf;
r.length = strlen(sendbuf) + 1;
isc_socket_dscp(s2, 056); /* EF */
- strcpy(sendbuf, "Hello");
+ snprintf(sendbuf, sizeof(sendbuf), "Hello");
r.base = (void *) sendbuf;
r.length = strlen(sendbuf) + 1;
* Copy directory name. Need to have enough space for the name,
* a possible path separator, the wildcard, and the final NUL.
*/
- if (strlen(dirname) + 3 > sizeof(dir->dirname))
+ if (strlen(dirname) + 3 > sizeof(dir->dirname)) {
/* XXXDCL ? */
return (ISC_R_NOSPACE);
- strcpy(dir->dirname, dirname);
+ }
+ strlcpy(dir->dirname, dirname, sizeof(dir->dirname));
/*
* Append path separator, if needed, and "*".
*/
dir->handle = opendir(dirname);
- if (dir->handle == NULL)
- return isc__errno2result(errno);
+ if (dir->handle == NULL) {
+ return (isc__errno2result(errno));
+ }
return (result);
}
* Make sure that the space for the name is long enough.
*/
if (sizeof(dir->entry.name) <= strlen(entry->d_name))
- return (ISC_R_UNEXPECTED);
+ return (ISC_R_UNEXPECTED);
- strcpy(dir->entry.name, entry->d_name);
+ strlcpy(dir->entry.name, entry->d_name, sizeof(dir->entry.name));
/*
* Some dirents have d_namlen, but it is not portable.
strncpy(buf, path, s - path + 1);
buf[s - path + 1] = '\0';
- strcat(buf, templet);
+ strlcat(buf, templet, buflen);
} else {
if ((strlen(templet) + 1) > buflen)
return (ISC_R_NOSPACE);
- strcpy(buf, templet);
+ strlcpy(buf, templet, buflen);
}
return (ISC_R_SUCCESS);
cwd = getcwd(dirname, length);
if (cwd == NULL) {
- if (errno == ERANGE)
+ if (errno == ERANGE) {
result = ISC_R_NOSPACE;
- else
+ } else {
result = isc__errno2result(errno);
+ }
} else {
- if (strlen(dirname) + 1 == length)
+ if (strlen(dirname) + 1 == length) {
result = ISC_R_NOSPACE;
- else if (dirname[1] != '\0')
- strcat(dirname, "/");
+ } else if (dirname[1] != '\0') {
+ strlcat(dirname, "/", length);
+ }
}
return (result);
return (result);
if (strlen(path) + strlen(filename) + 1 > pathlen)
return (ISC_R_NOSPACE);
- strcat(path, filename);
+ strlcat(path, filename, pathlen);
return (ISC_R_SUCCESS);
}
#include <isc/socket.h>
#include <isc/stats.h>
#include <isc/strerror.h>
+#include <isc/string.h>
#include <isc/task.h>
#include <isc/thread.h>
#include <isc/util.h>
REQUIRE(sockaddr->type.sa.sa_family == AF_UNIX);
INSIST(strlen(sockaddr->type.sunix.sun_path) < sizeof(path));
- strcpy(path, sockaddr->type.sunix.sun_path);
+ strlcpy(path, sockaddr->type.sunix.sun_path, sizeof(path));
#ifdef NEED_SECURE_DIRECTORY
slash = strrchr(path, '/');
if (slash != NULL) {
- if (slash != path)
+ if (slash != path) {
*slash = '\0';
- else
- strcpy(path, "/");
- } else
- strcpy(path, ".");
+ } else {
+ strlcpy(path, "/", sizeof(path));
+ }
+ } else {
+ strlcpy(path, ".", sizeof(path));
+ }
#endif
if (chmod(path, perm) < 0) {
if (strlen(dirname) + 3 > sizeof(dir->dirname))
/* XXXDCL ? */
return (ISC_R_NOSPACE);
- strcpy(dir->dirname, dirname);
+ strlcpy(dir->dirname, dirname, sizeof(dir->dirname));
/*
* Append path separator, if needed, and "*".
/*
* Make sure that the space for the name is long enough.
*/
- strcpy(dir->entry.name, dir->entry.find_data.cFileName);
+ strlcpy(dir->entry.name, dir->entry.find_data.cFileName,
+ sizeof(dir->entry.name));
dir->entry.length = strlen(dir->entry.name);
return (ISC_R_SUCCESS);
/*
* Fill in the data for the first entry of the directory.
*/
- strcpy(dir->entry.name, dir->entry.find_data.cFileName);
+ strlcpy(dir->entry.name, dir->entry.find_data.cFileName,
+ sizeof(dir->entry.name));
dir->entry.length = strlen(dir->entry.name);
dir->entry_filled = ISC_TRUE;
*/
if (stat(newname, &sbuf) == 0) {
exists = TRUE;
- strcpy(buf, newname);
- strcat(buf, ".XXXXX");
+ strlcpy(buf, newname, sizeof(buf));
+ strlcat(buf, ".XXXXX", sizeof(buf));
tmpfd = mkstemp(buf, ISC_TRUE);
if (tmpfd > 0)
_close(tmpfd);
strncpy(buf, path, s - path + 1);
buf[s - path + 1] = '\0';
- strcat(buf, templet);
+ strlcat(buf, templet, buflen);
} else {
if ((strlen(templet) + 1) > buflen)
return (ISC_R_NOSPACE);
- strcpy(buf, templet);
+ strlcpy(buf, templet, buflen);
}
return (ISC_R_SUCCESS);
if (namelen <= strlen(s))
return (ISC_R_NOSPACE);
- strcpy(progname, s);
+ strlcpy(progname, s, namelen);
return (ISC_R_SUCCESS);
}
if (len >= namelen)
return (ISC_R_NOSPACE);
- strncpy(progname, s, len);
+ strlcpy(progname, s, len);
progname[len] = '\0';
return (ISC_R_SUCCESS);
}
else if ((filename[0] == '\\') && (filename[1] == '\\')) {
/* Find the machine and share name and rebuild the UNC */
- strcpy(tmpbuf, filename);
+ strlcpy(tmpbuf, filename, sizeof(tmpbuf));
machinename = strtok(tmpbuf, "\\");
sharename = strtok(NULL, "\\");
- strcpy(drive, "\\\\");
- strcat(drive, machinename);
- strcat(drive, "\\");
- strcat(drive, sharename);
- strcat(drive, "\\");
+ strlcpy(drive, "\\\\", sizeof(drive));
+ strlcat(drive, machinename, sizeof(drive));
+ strlcat(drive, "\\", sizeof(drive));
+ strlcat(drive, sharename, sizeof(drive));
+ strlcat(drive, "\\", sizeof(drive));
}
else /* Not determinable */
strcat(sys_conf_dir, "\\etc");
/* Added to avoid an assert on NULL value */
- strcpy(resolv_confFile, namedBase);
- strcat(resolv_confFile, "\\etc\\resolv.conf");
+ strlcpy(resolv_confFile, namedBase, sizeof(resolv_confFile));
+ strlcat(resolv_confFile, "\\etc\\resolv.conf",
+ sizeof(resolv_confFile));
Initialized = TRUE;
}
return (ISC_R_SUCCESS);
}
}
- if ((flags & CFG_ADDR_V4PREFIXOK) != 0 &&
- strlen(s) <= 15U) {
+ if ((flags & CFG_ADDR_V4PREFIXOK) != 0 && strlen(s) <= 15U) {
char buf[64];
int i;
- strcpy(buf, s);
+ strlcpy(buf, s, sizeof(buf));
for (i = 0; i < 3; i++) {
- strcat(buf, ".0");
+ strlcat(buf, ".0", sizeof(buf));
if (inet_pton(AF_INET, buf, &in4a) == 1) {
isc_netaddr_fromin(na, &in4a);
return (ISC_R_SUCCESS);
}
}
}
- if ((flags & CFG_ADDR_V6OK) != 0 &&
- strlen(s) <= 127U) {
+ if ((flags & CFG_ADDR_V6OK) != 0 && strlen(s) <= 127U) {
char buf[128]; /* see lib/bind9/getaddresses.c */
char *d; /* zone delimiter */
isc_uint32_t zone = 0; /* scope zone ID */
- strcpy(buf, s);
+ strlcpy(buf, s, sizeof(buf));
d = strchr(buf, '%');
if (d != NULL)
*d = '\0';
len = vsnprintf(message, sizeof(message), format, args);
#define ELIPSIS " ... "
- if (len >= sizeof(message))
+ if (len >= sizeof(message)) {
strcpy(message + sizeof(message) - sizeof(ELIPSIS) - 1,
ELIPSIS);
+ }
if ((flags & (CFG_LOG_NEAR|CFG_LOG_BEFORE|CFG_LOG_NOPREP)) != 0) {
isc_region_t r;
dns_rdataclass_format(rdataset->rdclass, classbuf,
sizeof(classbuf));
} else {
- strcpy(typebuf, "-");
- strcpy(classbuf, "-");
+ strlcpy(typebuf, "-", sizeof(typebuf));
+ strlcpy(classbuf, "-", sizeof(classbuf));
}
UNLOCK(&client->query.fetchlock);
fprintf(f, "; client %s%s%s: id %u '%s/%s/%s'%s%s "