summaryrefslogtreecommitdiffstats
path: root/libc/dns/nameser/ns_print.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/dns/nameser/ns_print.c')
-rw-r--r--libc/dns/nameser/ns_print.c96
1 files changed, 45 insertions, 51 deletions
diff --git a/libc/dns/nameser/ns_print.c b/libc/dns/nameser/ns_print.c
index 0a6a1d6..32c8715 100644
--- a/libc/dns/nameser/ns_print.c
+++ b/libc/dns/nameser/ns_print.c
@@ -48,12 +48,6 @@ __RCSID("$NetBSD: ns_print.c,v 1.11 2012/03/13 21:13:39 christos Exp $");
#include <string.h>
#include <ctype.h>
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) ((int)strlen(sprintf/**/x))
-#else
-# define SPRINTF(x) (sprintf x)
-#endif
-
#ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y))
#endif
@@ -155,7 +149,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
*/
T(x = ns_format_ttl(ttl, buf, buflen));
addlen((size_t)x, &buf, &buflen);
- len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
+ len = snprintf(tmp, sizeof(tmp), " %s %s", p_class(class), p_type(type));
T(addstr(tmp, (size_t)len, &buf, &buflen));
T(spaced = addtab((size_t)(x + len), (size_t)16, spaced, &buf, &buflen));
@@ -218,7 +212,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
/* Serial number. */
t = ns_get32(rdata); rdata += NS_INT32SZ;
T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
- len = SPRINTF((tmp, "%lu", t));
+ len = snprintf(tmp, sizeof(tmp), "%lu", t);
T(addstr(tmp, (size_t)len, &buf, &buflen));
T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
T(addstr("; serial\n", (size_t)9, &buf, &buflen));
@@ -275,7 +269,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
/* Priority. */
t = ns_get16(rdata);
rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u ", t));
+ len = snprintf(tmp, sizeof(tmp), "%u ", t);
T(addstr(tmp, (size_t)len, &buf, &buflen));
/* Target. */
@@ -293,7 +287,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
/* Priority. */
t = ns_get16(rdata);
rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u ", t));
+ len = snprintf(tmp, sizeof(tmp), "%u ", t);
T(addstr(tmp, (size_t)len, &buf, &buflen));
/* Name1. */
@@ -344,7 +338,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
char t[255];
/* XXX protocol format checking? */
- (void) loc_ntoa(rdata, t);
+ (void) loc_ntoa(rdata, t, sizeof(t));
T(addstr(t, strlen(t), &buf, &buflen));
break;
}
@@ -359,7 +353,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
/* Order, Precedence. */
order = ns_get16(rdata); rdata += NS_INT16SZ;
preference = ns_get16(rdata); rdata += NS_INT16SZ;
- len = SPRINTF((t, "%u %u ", order, preference));
+ len = snprintf(t, sizeof(t), "%u %u ", order, preference);
T(addstr(t, (size_t)len, &buf, &buflen));
/* Flags. */
@@ -401,7 +395,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
priority = ns_get16(rdata); rdata += NS_INT16SZ;
weight = ns_get16(rdata); rdata += NS_INT16SZ;
port = ns_get16(rdata); rdata += NS_INT16SZ;
- len = SPRINTF((t, "%u %u %u ", priority, weight, port));
+ len = snprintf(t, sizeof(t), "%u %u %u ", priority, weight, port);
T(addstr(t, (size_t)len, &buf, &buflen));
/* Server. */
@@ -432,7 +426,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
rdata += NS_INADDRSZ;
/* Protocol. */
- len = SPRINTF((tmp, " %u ( ", *rdata));
+ len = snprintf(tmp, sizeof(tmp), " %u ( ", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata += NS_INT8SZ;
@@ -449,7 +443,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
lcnt = 10;
spaced = 0;
}
- len = SPRINTF((tmp, "%d ", n));
+ len = snprintf(tmp, sizeof(tmp), "%d ", n);
T(addstr(tmp, (size_t)len, &buf, &buflen));
lcnt--;
}
@@ -480,8 +474,8 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
keyflags = ns_get16(rdata); rdata += NS_INT16SZ;
protocol = *rdata++;
algorithm = *rdata++;
- len = SPRINTF((tmp, "0x%04x %u %u",
- keyflags, protocol, algorithm));
+ len = snprintf(tmp, sizeof(tmp), "0x%04x %u %u",
+ keyflags, protocol, algorithm);
T(addstr(tmp, (size_t)len, &buf, &buflen));
/* Public key data. */
@@ -502,7 +496,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
}
if (len > 15)
T(addstr(" )", (size_t)2, &buf, &buflen));
- n = SPRINTF((tmp, " ; key_tag= %u", key_id));
+ n = snprintf(tmp, sizeof(tmp), " ; key_tag= %u", key_id);
T(addstr(tmp, (size_t)n, &buf, &buflen));
break;
@@ -524,25 +518,25 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
algorithm = *rdata++;
labels = *rdata++;
t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s %d %d %lu ",
- p_type((int)typ), algorithm, labels, t));
+ len = snprintf(tmp, sizeof(tmp), "%s %d %d %lu ",
+ p_type((int)typ), algorithm, labels, t);
T(addstr(tmp, (size_t)len, &buf, &buflen));
if (labels > (u_int)dn_count_labels(name))
goto formerr;
/* Signature expiry. */
t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+ len = snprintf(tmp, sizeof(tmp), "%s ", p_secstodate(t));
T(addstr(tmp, (size_t)len, &buf, &buflen));
/* Time signed. */
t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+ len = snprintf(tmp, sizeof(tmp), "%s ", p_secstodate(t));
T(addstr(tmp, (size_t)len, &buf, &buflen));
/* Signature Footprint. */
footprint = ns_get16(rdata); rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u ", footprint));
+ len = snprintf(tmp, sizeof(tmp), "%u ", footprint);
T(addstr(tmp, (size_t)len, &buf, &buflen));
/* Signer's name. */
@@ -579,7 +573,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
n = edata - rdata;
for (c = 0; c < n*8; c++)
if (NS_NXT_BIT_ISSET(c, rdata)) {
- len = SPRINTF((tmp, " %s", p_type((int)c)));
+ len = snprintf(tmp, sizeof(tmp), " %s", p_type((int)c));
T(addstr(tmp, (size_t)len, &buf, &buflen));
}
break;
@@ -596,7 +590,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
key_tag = ns_get16(rdata); rdata += NS_INT16SZ;
alg = (u_int) *rdata++;
- len = SPRINTF((tmp1, "%d %d %d ", c_type, key_tag, alg));
+ len = snprintf(tmp1, sizeof(tmp1), "%d %d %d ", c_type, key_tag, alg);
T(addstr(tmp1, (size_t)len, &buf, &buflen));
siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
if (siz > sizeof(base64_cert) * 3/4) {
@@ -640,12 +634,12 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
/* Inception. */
t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+ len = snprintf(tmp, sizeof(tmp), "%s ", p_secstodate(t));
T(addstr(tmp, (size_t)len, &buf, &buflen));
/* Experation. */
t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+ len = snprintf(tmp, sizeof(tmp), "%s ", p_secstodate(t));
T(addstr(tmp, (size_t)len, &buf, &buflen));
/* Mode , Error, Key Size. */
@@ -653,7 +647,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
mode = ns_get16(rdata); rdata += NS_INT16SZ;
err = ns_get16(rdata); rdata += NS_INT16SZ;
keysize = ns_get16(rdata); rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u %u %u ", mode, err, keysize));
+ len = snprintf(tmp, sizeof(tmp), "%u %u %u ", mode, err, keysize);
T(addstr(tmp, (size_t)len, &buf, &buflen));
/* XXX need to dump key, print otherdata length & other data */
@@ -670,7 +664,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
n = ns_get16(rdata); rdata += INT16SZ;
rdata += n; /* sig */
n = ns_get16(rdata); rdata += INT16SZ; /* original id */
- sprintf(buf, "%d", ns_get16(rdata));
+ snprintf(buf, buflen, "%d", ns_get16(rdata));
rdata += INT16SZ;
addlen(strlen(buf), &buf, &buflen);
break;
@@ -682,7 +676,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
/* prefix length */
if (rdlen == 0U) goto formerr;
- len = SPRINTF((tmp, "%d ", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%d ", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
pbit = *rdata;
if (pbit > 128) goto formerr;
@@ -710,7 +704,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
}
case ns_t_opt: {
- len = SPRINTF((tmp, "%u bytes", class));
+ len = snprintf(tmp, sizeof(tmp), "%u bytes", class);
T(addstr(tmp, (size_t)len, &buf, &buflen));
break;
}
@@ -724,21 +718,21 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
if (rdlen < 4U) goto formerr;
t = ns_get16(rdata);
rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u ", t));
+ len = snprintf(tmp, sizeof(tmp), "%u ", t);
T(addstr(tmp, (size_t)len, &buf, &buflen));
} else
if (rdlen < 2U) goto formerr;
- len = SPRINTF((tmp, "%u ", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%u ", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
- len = SPRINTF((tmp, "%u ", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%u ", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
while (rdata < edata) {
- len = SPRINTF((tmp, "%02X", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%02X", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
}
@@ -749,17 +743,17 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
case ns_t_nsec3param: {
u_int t, w, l, j, k, c;
- len = SPRINTF((tmp, "%u ", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%u ", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
- len = SPRINTF((tmp, "%u ", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%u ", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
t = ns_get16(rdata);
rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u ", t));
+ len = snprintf(tmp, sizeof(tmp), "%u ", t);
T(addstr(tmp, (size_t)len, &buf, &buflen));
t = *rdata++;
@@ -767,7 +761,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
T(addstr("-", 1, &buf, &buflen));
} else {
while (t-- > 0) {
- len = SPRINTF((tmp, "%02X", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%02X", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
}
@@ -851,7 +845,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
if ((rdata[j] & (0x80 >> k)) == 0)
continue;
c = w * 256 + j * 8 + k;
- len = SPRINTF((tmp, " %s", p_type((ns_type)c)));
+ len = snprintf(tmp, sizeof(tmp), " %s", p_type((ns_type)c));
T(addstr(tmp, (size_t)len, &buf, &buflen));
}
}
@@ -875,7 +869,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
if ((rdata[j] & (0x80 >> k)) == 0)
continue;
c = w * 256 + j * 8 + k;
- len = SPRINTF((tmp, " %s", p_type((ns_type)c)));
+ len = snprintf(tmp, sizeof(tmp), " %s", p_type((ns_type)c));
T(addstr(tmp, (size_t)len, &buf, &buflen));
}
}
@@ -949,15 +943,15 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
goto hexify;
}
- len = SPRINTF((tmp, "%u ", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%u ", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
- len = SPRINTF((tmp, "%u ", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%u ", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
- len = SPRINTF((tmp, "%u ", *rdata));
+ len = snprintf(tmp, sizeof(tmp), "%u ", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
@@ -1030,11 +1024,11 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
const char *str = "record too long to print";
T(addstr(str, strlen(str), &buf, &buflen));
} else {
- len = sprintf(tmp, "( %u ", algorithm);
+ len = snprintf(tmp, sizeof(tmp), "( %u ", algorithm);
T(addstr(tmp, (size_t)len, &buf, &buflen));
for (i = 0; i < hip_len; i++) {
- len = sprintf(tmp, "%02X", *rdata);
+ len = snprintf(tmp, sizeof(tmp), "%02X", *rdata);
T(addstr(tmp, (size_t)len, &buf, &buflen));
rdata++;
}
@@ -1069,23 +1063,23 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
int n, m;
char *p;
- len = SPRINTF((tmp, "\\# %u%s\t; %s", (unsigned)(edata - rdata),
- rdlen != 0U ? " (" : "", comment));
+ len = snprintf(tmp, sizeof(tmp), "\\# %u%s\t; %s", (unsigned)(edata - rdata),
+ rdlen != 0U ? " (" : "", comment);
T(addstr(tmp, (size_t)len, &buf, &buflen));
while (rdata < edata) {
p = tmp;
- p += SPRINTF((p, "\n\t"));
+ p += snprintf(p, sizeof(tmp), "\n\t");
spaced = 0;
n = MIN(16, (int)(edata - rdata));
for (m = 0; m < n; m++)
- p += SPRINTF((p, "%02x ", rdata[m]));
+ p += snprintf(p, sizeof(tmp) - (p - tmp), "%02x ", rdata[m]);
T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen));
if (n < 16) {
T(addstr(")", (size_t)1, &buf, &buflen));
T(addtab((size_t)(p - tmp + 1), (size_t)48, spaced, &buf, &buflen));
}
p = tmp;
- p += SPRINTF((p, "; "));
+ p += snprintf(p, sizeof(tmp), "; ");
for (m = 0; m < n; m++)
*p++ = (isascii(rdata[m]) && isprint(rdata[m]))
? rdata[m]