summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/bind/lib/dns/byaddr.c11
-rw-r--r--usr.sbin/bind/lib/dns/masterdump.c3
-rw-r--r--usr.sbin/bind/lib/dns/message.c14
-rw-r--r--usr.sbin/bind/lib/dns/name.c6
-rw-r--r--usr.sbin/bind/lib/dns/rdata.c14
-rw-r--r--usr.sbin/bind/lib/dns/resolver.c2
-rw-r--r--usr.sbin/bind/lib/dns/time.c8
-rw-r--r--usr.sbin/bind/lib/isc/lex.c6
-rw-r--r--usr.sbin/bind/lib/isc/log.c21
-rw-r--r--usr.sbin/bind/lib/isc/sockaddr.c4
-rw-r--r--usr.sbin/bind/lib/isccc/cc.c4
-rw-r--r--usr.sbin/bind/lib/isccfg/parser.c10
-rw-r--r--usr.sbin/bind/lib/lwres/getnameinfo.c2
-rw-r--r--usr.sbin/bind/lib/lwres/lwinetntop.c7
-rw-r--r--usr.sbin/bind/lib/tests/t_api.c8
15 files changed, 66 insertions, 54 deletions
diff --git a/usr.sbin/bind/lib/dns/byaddr.c b/usr.sbin/bind/lib/dns/byaddr.c
index f67331cd35f..97b93061aab 100644
--- a/usr.sbin/bind/lib/dns/byaddr.c
+++ b/usr.sbin/bind/lib/dns/byaddr.c
@@ -85,11 +85,12 @@ dns_byaddr_createptrname(isc_netaddr_t *address, isc_boolean_t nibble,
bytes = (unsigned char *)(&address->type);
if (address->family == AF_INET) {
- (void)sprintf(textname, "%u.%u.%u.%u.in-addr.arpa.",
- (bytes[3] & 0xff),
- (bytes[2] & 0xff),
- (bytes[1] & 0xff),
- (bytes[0] & 0xff));
+ (void)snprintf(textname, sizeof(textname),
+ "%u.%u.%u.%u.in-addr.arpa.",
+ (bytes[3] & 0xff),
+ (bytes[2] & 0xff),
+ (bytes[1] & 0xff),
+ (bytes[0] & 0xff));
} else if (address->family == AF_INET6) {
if (nibble) {
cp = textname;
diff --git a/usr.sbin/bind/lib/dns/masterdump.c b/usr.sbin/bind/lib/dns/masterdump.c
index 95f9ab6364b..e52f5631824 100644
--- a/usr.sbin/bind/lib/dns/masterdump.c
+++ b/usr.sbin/bind/lib/dns/masterdump.c
@@ -395,7 +395,8 @@ rdataset_totext(dns_rdataset_t *rdataset,
unsigned int length;
INDENT_TO(ttl_column);
- length = sprintf(ttlbuf, "%u", rdataset->ttl);
+ length = snprintf(ttlbuf, sizeof(ttlbuf), "%u",
+ rdataset->ttl);
INSIST(length <= sizeof ttlbuf);
isc_buffer_availableregion(target, &r);
if (r.length < length)
diff --git a/usr.sbin/bind/lib/dns/message.c b/usr.sbin/bind/lib/dns/message.c
index ad07d7d97d8..5ce0157eba1 100644
--- a/usr.sbin/bind/lib/dns/message.c
+++ b/usr.sbin/bind/lib/dns/message.c
@@ -2980,7 +2980,7 @@ dns_message_totext(dns_message_t *msg, const dns_master_style_t *style,
ADD_STRING(target, ", status: ");
ADD_STRING(target, rcodetext[msg->rcode]);
ADD_STRING(target, ", id: ");
- sprintf(buf, "%6u", msg->id);
+ snprintf(buf, sizeof(buf), "%6u", msg->id);
ADD_STRING(target, buf);
ADD_STRING(target, "\n;; flags: ");
if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
@@ -3002,24 +3002,28 @@ dns_message_totext(dns_message_t *msg, const dns_master_style_t *style,
} else {
ADD_STRING(target, "; ZONE: ");
}
- sprintf(buf, "%1u", msg->counts[DNS_SECTION_QUESTION]);
+ snprintf(buf, sizeof(buf), "%1u",
+ msg->counts[DNS_SECTION_QUESTION]);
ADD_STRING(target, buf);
if (msg->opcode != dns_opcode_update) {
ADD_STRING(target, ", ANSWER: ");
} else {
ADD_STRING(target, ", PREREQ: ");
}
- sprintf(buf, "%1u", msg->counts[DNS_SECTION_ANSWER]);
+ snprintf(buf, sizeof(buf), "%1u",
+ msg->counts[DNS_SECTION_ANSWER]);
ADD_STRING(target, buf);
if (msg->opcode != dns_opcode_update) {
ADD_STRING(target, ", AUTHORITY: ");
} else {
ADD_STRING(target, ", UPDATE: ");
}
- sprintf(buf, "%1u", msg->counts[DNS_SECTION_AUTHORITY]);
+ snprintf(buf, sizeof(buf), "%1u",
+ msg->counts[DNS_SECTION_AUTHORITY]);
ADD_STRING(target, buf);
ADD_STRING(target, ", ADDITIONAL: ");
- sprintf(buf, "%1u", msg->counts[DNS_SECTION_ADDITIONAL]);
+ snprintf(buf, sizeof buf, "%1u",
+ msg->counts[DNS_SECTION_ADDITIONAL]);
ADD_STRING(target, buf);
ADD_STRING(target, "\n");
}
diff --git a/usr.sbin/bind/lib/dns/name.c b/usr.sbin/bind/lib/dns/name.c
index 6e2eb5e5155..73b3aaf3fc8 100644
--- a/usr.sbin/bind/lib/dns/name.c
+++ b/usr.sbin/bind/lib/dns/name.c
@@ -1782,10 +1782,12 @@ dns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot,
trem--;
nlen--;
} else {
+ char buf[5];
if (trem < 4)
return (ISC_R_NOSPACE);
- sprintf(tdata, "\\%03u",
- c);
+ snprintf(buf, sizeof(buf),
+ "\\%03u", c);
+ memcpy(tdata, buf, 4);
tdata += 4;
trem -= 4;
ndata++;
diff --git a/usr.sbin/bind/lib/dns/rdata.c b/usr.sbin/bind/lib/dns/rdata.c
index 3fba2b5b5dd..0160e04e94d 100644
--- a/usr.sbin/bind/lib/dns/rdata.c
+++ b/usr.sbin/bind/lib/dns/rdata.c
@@ -777,11 +777,11 @@ rdata_totext(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
TOTEXTSWITCH
if (use_default) {
- sprintf(buf, "\\# ");
+ strlcpy(buf, "\\# ", sizeof(buf));
result = str_totext(buf, target);
dns_rdata_toregion(rdata, &sr);
INSIST(sr.length < 65536);
- sprintf(buf, "%u", sr.length);
+ snprintf(buf, sizeof(buf), "%u", sr.length);
result = str_totext(buf, target);
if (sr.length != 0 && result == ISC_R_SUCCESS) {
if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
@@ -1015,7 +1015,7 @@ dns_mnemonic_totext(unsigned int value, isc_buffer_t *target,
}
i++;
}
- sprintf(buf, "%u", value);
+ snprintf(buf, sizeof buf, "%u", value);
return (str_totext(buf, target));
}
@@ -1100,7 +1100,7 @@ dns_rdataclass_totext(dns_rdataclass_t rdclass, isc_buffer_t *target) {
case dns_rdataclass_reserved0:
return (str_totext("RESERVED0", target));
default:
- sprintf(buf, "CLASS%u", rdclass);
+ snprintf(buf, sizeof(buf), "CLASS%u", rdclass);
return (str_totext(buf, target));
}
}
@@ -1175,7 +1175,7 @@ dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) {
char buf[sizeof "TYPE65536"];
if (type > 255) {
- sprintf(buf, "TYPE%u", type);
+ snprintf(buf, sizeof buf, "TYPE%u", type);
return (str_totext(buf, target));
}
@@ -1369,7 +1369,7 @@ txt_totext(isc_region_t *source, isc_buffer_t *target) {
if (*sp < 0x20 || *sp >= 0x7f) {
if (tl < 4)
return (ISC_R_NOSPACE);
- sprintf(tp, "\\%03u", *sp++);
+ snprintf(tp, 5, "\\%03u", *sp++);
tp += 4;
tl -= 4;
continue;
@@ -1942,7 +1942,7 @@ btoa_totext(unsigned char *inbuf, int inbuflen, isc_buffer_t *target) {
* Put byte count and checksum information at end of buffer,
* delimited by 'x'
*/
- sprintf(buf, "x %d %x %x %x", inbuflen, Ceor, Csum, Crot);
+ snprintf(buf, sizeof(buf), "x %d %x %x %x", inbuflen, Ceor, Csum, Crot);
return (str_totext(buf, target));
}
diff --git a/usr.sbin/bind/lib/dns/resolver.c b/usr.sbin/bind/lib/dns/resolver.c
index 54b00fedfc2..b5950dd726e 100644
--- a/usr.sbin/bind/lib/dns/resolver.c
+++ b/usr.sbin/bind/lib/dns/resolver.c
@@ -4682,7 +4682,7 @@ dns_resolver_create(dns_view_t *view,
DESTROYLOCK(&res->buckets[i].lock);
goto cleanup_buckets;
}
- sprintf(name, "res%u", i);
+ snprintf(name, sizeof(name), "res%u", i);
isc_task_setname(res->buckets[i].task, name, res);
ISC_LIST_INIT(res->buckets[i].fctxs);
res->buckets[i].exiting = ISC_FALSE;
diff --git a/usr.sbin/bind/lib/dns/time.c b/usr.sbin/bind/lib/dns/time.c
index 07d1b0ad6bb..4081e8e8a49 100644
--- a/usr.sbin/bind/lib/dns/time.c
+++ b/usr.sbin/bind/lib/dns/time.c
@@ -74,10 +74,10 @@ dns_time64_totext(isc_int64_t t, isc_buffer_t *target) {
tm.tm_min++;
}
tm.tm_sec = (int)t;
- /* yy mm dd HH MM SS */
- sprintf(buf, "%04d%02d%02d%02d%02d%02d",
- tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec);
+ /* yyyy mm dd HH MM SS */
+ snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02d",
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, tm.tm_sec);
isc_buffer_availableregion(target, &region);
l = strlen(buf);
diff --git a/usr.sbin/bind/lib/isc/lex.c b/usr.sbin/bind/lib/isc/lex.c
index 59cf9c793fd..8f87d1cef81 100644
--- a/usr.sbin/bind/lib/isc/lex.c
+++ b/usr.sbin/bind/lib/isc/lex.c
@@ -251,8 +251,7 @@ isc_lex_openstream(isc_lex_t *lex, FILE *stream) {
REQUIRE(VALID_LEX(lex));
- /* This is safe. */
- sprintf(name, "stream-%p", stream);
+ snprintf(name, sizeof(name), "stream-%p", stream);
return (new_source(lex, ISC_TRUE, ISC_FALSE, stream, name));
}
@@ -267,8 +266,7 @@ isc_lex_openbuffer(isc_lex_t *lex, isc_buffer_t *buffer) {
REQUIRE(VALID_LEX(lex));
- /* This is safe. */
- sprintf(name, "buffer-%p", buffer);
+ snprintf(name, sizeof(name), "buffer-%p", buffer);
return (new_source(lex, ISC_FALSE, ISC_FALSE, buffer, name));
}
diff --git a/usr.sbin/bind/lib/isc/log.c b/usr.sbin/bind/lib/isc/log.c
index 82d32c41df6..6a57b566602 100644
--- a/usr.sbin/bind/lib/isc/log.c
+++ b/usr.sbin/bind/lib/isc/log.c
@@ -1468,18 +1468,19 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
if ((channel->flags & ISC_LOG_PRINTLEVEL) != 0 &&
level_string[0] == '\0') {
if (level < ISC_LOG_CRITICAL)
- sprintf(level_string,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_LOG,
- ISC_MSG_LEVEL,
- "level %d: "),
- level);
+ snprintf(level_string, sizeof(level_string),
+ isc_msgcat_get(isc_msgcat,
+ ISC_MSGSET_LOG,
+ ISC_MSG_LEVEL,
+ "level %d: "),
+ level);
else if (level > ISC_LOG_DYNAMIC)
- sprintf(level_string, "%s %d: ",
- log_level_strings[0], level);
+ snprintf(level_string, sizeof(level_string),
+ "%s %d: ", log_level_strings[0],
+ level);
else
- sprintf(level_string, "%s: ",
- log_level_strings[-level]);
+ snprintf(level_string, sizeof(level_string),
+ "%s: ", log_level_strings[-level]);
}
/*
diff --git a/usr.sbin/bind/lib/isc/sockaddr.c b/usr.sbin/bind/lib/isc/sockaddr.c
index 3712e765092..b37b51e763b 100644
--- a/usr.sbin/bind/lib/isc/sockaddr.c
+++ b/usr.sbin/bind/lib/isc/sockaddr.c
@@ -120,10 +120,10 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) {
*/
switch (sockaddr->type.sa.sa_family) {
case AF_INET:
- sprintf(pbuf, "%u", ntohs(sockaddr->type.sin.sin_port));
+ snprintf(pbuf, sizeof(pbuf), "%u", ntohs(sockaddr->type.sin.sin_port));
break;
case AF_INET6:
- sprintf(pbuf, "%u", ntohs(sockaddr->type.sin6.sin6_port));
+ snprintf(pbuf, sizeof(pbuf), "%u", ntohs(sockaddr->type.sin6.sin6_port));
break;
default:
return (ISC_R_FAILURE);
diff --git a/usr.sbin/bind/lib/isccc/cc.c b/usr.sbin/bind/lib/isccc/cc.c
index 08dd4f93b17..342a8d5855d 100644
--- a/usr.sbin/bind/lib/isccc/cc.c
+++ b/usr.sbin/bind/lib/isccc/cc.c
@@ -647,7 +647,7 @@ isccc_cc_defineuint32(isccc_sexpr_t *alist, const char *key, isc_uint32_t i)
size_t len;
isccc_region_t r;
- sprintf(b, "%u", i);
+ snprintf(b, sizeof(b), "%u", i);
len = strlen(b);
r.rstart = (unsigned char *)b;
r.rend = (unsigned char *)b + len;
@@ -792,7 +792,7 @@ isccc_cc_checkdup(isccc_symtab_t *symtab, isccc_sexpr_t *message,
key = malloc(len);
if (key == NULL)
return (ISC_R_NOMEMORY);
- sprintf(key, "%s;%s;%s;%s", _frm, _to, _ser, _tim);
+ snprintf(key, len, "%s;%s;%s;%s", _frm, _to, _ser, _tim);
value.as_uinteger = now;
result = isccc_symtab_define(symtab, key, ISCCC_SYMTYPE_CCDUP, value,
isccc_symexists_reject);
diff --git a/usr.sbin/bind/lib/isccfg/parser.c b/usr.sbin/bind/lib/isccfg/parser.c
index 9bad2b1541d..84c0a1b7fb3 100644
--- a/usr.sbin/bind/lib/isccfg/parser.c
+++ b/usr.sbin/bind/lib/isccfg/parser.c
@@ -1649,7 +1649,8 @@ parse_unitstring(char *str, isc_resourcevalue_t *valuep) {
static void
print_uint64(cfg_printer_t *pctx, cfg_obj_t *obj) {
char buf[32];
- sprintf(buf, "%" ISC_PRINT_QUADFORMAT "u", obj->value.uint64);
+ snprintf(buf, sizeof(buf), "%" ISC_PRINT_QUADFORMAT "u",
+ obj->value.uint64);
print_cstr(pctx, buf);
}
@@ -3646,13 +3647,16 @@ parser_complain(cfg_parser_t *pctx, isc_boolean_t is_warning,
static char message[2048];
int level = ISC_LOG_ERROR;
const char *prep = "";
+ size_t len;
if (is_warning)
level = ISC_LOG_WARNING;
- sprintf(where, "%s:%u: ", current_file(pctx), pctx->line);
+ snprintf(where, sizeof(where), "%s:%u: ",
+ current_file(pctx), pctx->line);
- if ((unsigned int)vsprintf(message, format, args) >= sizeof message)
+ len = vsnprintf(message, sizeof(message), format, args);
+ if (len >= sizeof(message))
FATAL_ERROR(__FILE__, __LINE__,
"error message would overflow");
diff --git a/usr.sbin/bind/lib/lwres/getnameinfo.c b/usr.sbin/bind/lib/lwres/getnameinfo.c
index 0708b7a583a..df0756adb19 100644
--- a/usr.sbin/bind/lib/lwres/getnameinfo.c
+++ b/usr.sbin/bind/lib/lwres/getnameinfo.c
@@ -172,7 +172,7 @@ lwres_getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
*/
} else if ((flags & NI_NUMERICSERV) != 0 ||
(sp = getservbyport(port, proto)) == NULL) {
- sprintf(numserv, "%d", ntohs(port));
+ snprintf(numserv, sizeof(numserv), "%d", ntohs(port));
if ((strlen(numserv) + 1) > servlen)
ERR(ENI_MEMORY);
strcpy(serv, numserv);
diff --git a/usr.sbin/bind/lib/lwres/lwinetntop.c b/usr.sbin/bind/lib/lwres/lwinetntop.c
index 9509a2d9021..c9525ec55cf 100644
--- a/usr.sbin/bind/lib/lwres/lwinetntop.c
+++ b/usr.sbin/bind/lib/lwres/lwinetntop.c
@@ -83,9 +83,10 @@ static const char *
inet_ntop4(const unsigned char *src, char *dst, size_t size) {
static const char fmt[] = "%u.%u.%u.%u";
char tmp[sizeof "255.255.255.255"];
+ size_t len;
- if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size)
- {
+ len = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
+ if (len >= size) {
errno = ENOSPC;
return (NULL);
}
@@ -170,7 +171,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) {
tp += strlen(tp);
break;
}
- tp += sprintf(tp, "%x", words[i]);
+ tp += sprintf(tp, "%x", words[i]); /* XXX */
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) ==
diff --git a/usr.sbin/bind/lib/tests/t_api.c b/usr.sbin/bind/lib/tests/t_api.c
index 5f1fc441c3d..460f3ee03ee 100644
--- a/usr.sbin/bind/lib/tests/t_api.c
+++ b/usr.sbin/bind/lib/tests/t_api.c
@@ -253,7 +253,7 @@ main(int argc, char **argv) {
* Output start stanza to journal.
*/
- sprintf(T_buf, "%s:", argv[0]);
+ snprintf(T_buf, sizeof(T_buf), "%s:", argv[0]);
len = strlen(T_buf);
(void) t_getdate(T_buf + len, T_BIGBUF - len);
t_putinfo("S", T_buf);
@@ -334,7 +334,7 @@ main(int argc, char **argv) {
++tnum;
}
- sprintf(T_buf, "%s:", argv[0]);
+ snprintf(T_buf, sizeof(T_buf), "%s:", argv[0]);
len = strlen(T_buf);
(void) t_getdate(T_buf + len, T_BIGBUF - len);
t_putinfo("E", T_buf);
@@ -353,7 +353,7 @@ t_assert(const char *component, int anum, int class, const char *what, ...) {
* Format text to a buffer.
*/
va_start(args, what);
- (void)vsprintf(T_buf, what, args);
+ (void)vsnprintf(T_buf, sizeof(T_buf), what, args);
va_end(args);
(void)t_putinfo("A", T_buf);
@@ -365,7 +365,7 @@ t_info(const char *format, ...) {
va_list args;
va_start(args, format);
- (void) vsprintf(T_buf, format, args);
+ (void) vsnprintf(T_buf, sizeof(T_buf), format, args);
va_end(args);
(void) t_putinfo("I", T_buf);
}