summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorderaadt <>2002-07-25 21:55:30 +0000
committerderaadt <>2002-07-25 21:55:30 +0000
commit8092efea6856a632fe16c823f241d12cd8b791c6 (patch)
tree0227f0b4c8684499c6702f5f85c2cd44776b519f
parent38f8ca9fa51b59794faf1c8ca4e9b1b7c06eeb42 (diff)
downloadopenbsd-8092efea6856a632fe16c823f241d12cd8b791c6.tar.gz
openbsd-8092efea6856a632fe16c823f241d12cd8b791c6.tar.bz2
openbsd-8092efea6856a632fe16c823f241d12cd8b791c6.zip
more snprintf and strlcpy; help from millert
-rw-r--r--src/lib/libc/net/res_debug.c61
1 files changed, 48 insertions, 13 deletions
diff --git a/src/lib/libc/net/res_debug.c b/src/lib/libc/net/res_debug.c
index a1c88e24b3..2ea9173fe9 100644
--- a/src/lib/libc/net/res_debug.c
+++ b/src/lib/libc/net/res_debug.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_debug.c,v 1.13 2002/06/27 10:14:02 itojun Exp $ */ 1/* $OpenBSD: res_debug.c,v 1.14 2002/07/25 21:55:30 deraadt Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1985, 1990, 1993 4 * ++Copyright++ 1985, 1990, 1993
@@ -82,7 +82,7 @@
82static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; 82static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
83static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; 83static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $";
84#else 84#else
85static char rcsid[] = "$OpenBSD: res_debug.c,v 1.13 2002/06/27 10:14:02 itojun Exp $"; 85static char rcsid[] = "$OpenBSD: res_debug.c,v 1.14 2002/07/25 21:55:30 deraadt Exp $";
86#endif 86#endif
87#endif /* LIBC_SCCS and not lint */ 87#endif /* LIBC_SCCS and not lint */
88 88
@@ -105,6 +105,8 @@ static char rcsid[] = "$OpenBSD: res_debug.c,v 1.13 2002/06/27 10:14:02 itojun E
105extern const char *_res_opcodes[]; 105extern const char *_res_opcodes[];
106extern const char *_res_resultcodes[]; 106extern const char *_res_resultcodes[];
107 107
108static const char *loc_ntoal(const u_char *binary, char *ascii, int ascii_len);
109
108/* XXX: we should use getservbyport() instead. */ 110/* XXX: we should use getservbyport() instead. */
109static const char * 111static const char *
110dewks(wks) 112dewks(wks)
@@ -666,7 +668,7 @@ __p_rr(cp, msg, file)
666 case T_LOC: { 668 case T_LOC: {
667 char t[255]; 669 char t[255];
668 670
669 fprintf(file, "\t%s", loc_ntoa(cp, t)); 671 fprintf(file, "\t%s", loc_ntoal(cp, t, sizeof t));
670 cp += dlen; 672 cp += dlen;
671 break; 673 break;
672 } 674 }
@@ -1048,8 +1050,10 @@ p_time(value)
1048 u_int32_t value; 1050 u_int32_t value;
1049{ 1051{
1050 static char nbuf[40]; 1052 static char nbuf[40];
1053 char *ebuf;
1051 int secs, mins, hours, days; 1054 int secs, mins, hours, days;
1052 register char *p; 1055 register char *p;
1056 int tmp;
1053 1057
1054 if (value == 0) { 1058 if (value == 0) {
1055 strlcpy(nbuf, "0 secs", sizeof nbuf); 1059 strlcpy(nbuf, "0 secs", sizeof nbuf);
@@ -1067,28 +1071,50 @@ p_time(value)
1067 1071
1068#define PLURALIZE(x) x, (x == 1) ? "" : "s" 1072#define PLURALIZE(x) x, (x == 1) ? "" : "s"
1069 p = nbuf; 1073 p = nbuf;
1074 ebuf = nbuf + sizeof(nbuf);
1070 if (days) { 1075 if (days) {
1071 (void)sprintf(p, "%d day%s", PLURALIZE(days)); 1076 if ((tmp = snprintf(p, ebuf - p, "%d day%s",
1072 while (*++p); 1077 PLURALIZE(days))) >= ebuf - nbuf || tmp < 0)
1078 goto full;
1079 p += tmp;
1073 } 1080 }
1074 if (hours) { 1081 if (hours) {
1075 if (days) 1082 if (days)
1076 *p++ = ' '; 1083 *p++ = ' ';
1077 (void)sprintf(p, "%d hour%s", PLURALIZE(hours)); 1084 if (p >= ebuf)
1078 while (*++p); 1085 goto full;
1086 if ((tmp = snprintf(p, ebuf - p, "%d hour%s",
1087 PLURALIZE(hours))) >= ebuf - nbuf || tmp < 0)
1088 goto full;
1089 p += tmp;
1079 } 1090 }
1080 if (mins) { 1091 if (mins) {
1081 if (days || hours) 1092 if (days || hours)
1082 *p++ = ' '; 1093 *p++ = ' ';
1083 (void)sprintf(p, "%d min%s", PLURALIZE(mins)); 1094 if (p >= ebuf)
1084 while (*++p); 1095 goto full;
1096 if ((tmp = snprintf(p, ebuf - p, "%d min%s",
1097 PLURALIZE(mins))) >= ebuf - nbuf || tmp < 0)
1098 goto full;
1099 p += tmp;
1085 } 1100 }
1086 if (secs || ! (days || hours || mins)) { 1101 if (secs || ! (days || hours || mins)) {
1087 if (days || hours || mins) 1102 if (days || hours || mins)
1088 *p++ = ' '; 1103 *p++ = ' ';
1089 (void)sprintf(p, "%d sec%s", PLURALIZE(secs)); 1104 if (p >= ebuf)
1105 goto full;
1106 if ((tmp = snprintf(p, ebuf - p, "%d sec%s",
1107 PLURALIZE(secs))) >= ebuf - nbuf || tmp < 0)
1108 goto full;
1090 } 1109 }
1091 return (nbuf); 1110 return (nbuf);
1111full:
1112 p = nbuf + sizeof(nbuf) - 4;
1113 *p++ = '.';
1114 *p++ = '.';
1115 *p++ = '.';
1116 *p++ = '\0';
1117 return (nbuf);
1092} 1118}
1093 1119
1094/* 1120/*
@@ -1371,12 +1397,21 @@ loc_aton(ascii, binary)
1371 return (16); /* size of RR in octets */ 1397 return (16); /* size of RR in octets */
1372} 1398}
1373 1399
1374/* takes an on-the-wire LOC RR and formats it in a human readable format. */
1375const char * 1400const char *
1376loc_ntoa(binary, ascii) 1401loc_ntoa(binary, ascii)
1377 const u_char *binary; 1402 const u_char *binary;
1378 char *ascii; 1403 char *ascii;
1379{ 1404{
1405 return loc_ntoal(binary, ascii, 255);
1406}
1407
1408/* takes an on-the-wire LOC RR and formats it in a human readable format. */
1409static const char *
1410loc_ntoal(binary, ascii, ascii_len)
1411 const u_char *binary;
1412 char *ascii;
1413 int ascii_len;
1414{
1380 static char *error = "?"; 1415 static char *error = "?";
1381 register const u_char *cp = binary; 1416 register const u_char *cp = binary;
1382 1417
@@ -1396,7 +1431,7 @@ loc_ntoa(binary, ascii)
1396 versionval = *cp++; 1431 versionval = *cp++;
1397 1432
1398 if (versionval) { 1433 if (versionval) {
1399 sprintf(ascii, "; error: unknown LOC RR version"); 1434 snprintf(ascii, ascii_len, "; error: unknown LOC RR version");
1400 return (ascii); 1435 return (ascii);
1401 } 1436 }
1402 1437
@@ -1458,7 +1493,7 @@ loc_ntoa(binary, ascii)
1458 if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL) 1493 if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
1459 vpstr = error; 1494 vpstr = error;
1460 1495
1461 sprintf(ascii, 1496 snprintf(ascii, ascii_len,
1462 "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm", 1497 "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
1463 latdeg, latmin, latsec, latsecfrac, northsouth, 1498 latdeg, latmin, latsec, latsecfrac, northsouth,
1464 longdeg, longmin, longsec, longsecfrac, eastwest, 1499 longdeg, longmin, longsec, longsecfrac, eastwest,