summaryrefslogtreecommitdiff
path: root/lib/libc/net
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-24 21:22:38 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-24 21:22:38 +0000
commit614d3b268363cdee32aba3cafe8e123fe69ac75d (patch)
tree9662f1a62a0bd0d9512daf0fa448d0a7f051956a /lib/libc/net
parent899eab9f01ad712357176d191d1b6a49639c11e3 (diff)
try to use strlcpy and snprintf more; ok various
Diffstat (limited to 'lib/libc/net')
-rw-r--r--lib/libc/net/ethers.c8
-rw-r--r--lib/libc/net/inet_neta.c8
-rw-r--r--lib/libc/net/inet_ntop.c10
-rw-r--r--lib/libc/net/ipx_ntoa.c4
-rw-r--r--lib/libc/net/ns_ntoa.c4
-rw-r--r--lib/libc/net/rcmd.c5
-rw-r--r--lib/libc/net/res_debug.c29
-rw-r--r--lib/libc/net/res_query.c7
8 files changed, 40 insertions, 35 deletions
diff --git a/lib/libc/net/ethers.c b/lib/libc/net/ethers.c
index e7781438c1f..858ac5b3f37 100644
--- a/lib/libc/net/ethers.c
+++ b/lib/libc/net/ethers.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ethers.c,v 1.13 2002/02/16 21:27:23 millert Exp $ */
+/* $OpenBSD: ethers.c,v 1.14 2002/05/24 21:22:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -34,7 +34,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: ethers.c,v 1.13 2002/02/16 21:27:23 millert Exp $";
+static char rcsid[] = "$OpenBSD: ethers.c,v 1.14 2002/05/24 21:22:37 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -72,7 +72,7 @@ ether_ntoa(e)
return (NULL);
}
- (void)sprintf(a, "%02x:%02x:%02x:%02x:%02x:%02x",
+ (void)snprintf(a, sizeof a, "%02x:%02x:%02x:%02x:%02x:%02x",
e->ether_addr_octet[0], e->ether_addr_octet[1],
e->ether_addr_octet[2], e->ether_addr_octet[3],
e->ether_addr_octet[4], e->ether_addr_octet[5]);
@@ -138,7 +138,7 @@ ether_ntohost(hostname, e)
}
#ifdef YP
- sprintf(trybuf, "%x:%x:%x:%x:%x:%x",
+ snprintf(trybuf, sizeof trybuf, "%x:%x:%x:%x:%x:%x",
e->ether_addr_octet[0], e->ether_addr_octet[1],
e->ether_addr_octet[2], e->ether_addr_octet[3],
e->ether_addr_octet[4], e->ether_addr_octet[5]);
diff --git a/lib/libc/net/inet_neta.c b/lib/libc/net/inet_neta.c
index ffcddd8d912..881a328ab02 100644
--- a/lib/libc/net/inet_neta.c
+++ b/lib/libc/net/inet_neta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inet_neta.c,v 1.2 1997/04/05 21:13:12 millert Exp $ */
+/* $OpenBSD: inet_neta.c,v 1.3 2002/05/24 21:22:37 deraadt Exp $ */
/*
* Copyright (c) 1996 by Internet Software Consortium.
@@ -19,9 +19,9 @@
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
-static const char rcsid[] = "$Id: inet_neta.c,v 1.2 1997/04/05 21:13:12 millert Exp $";
+static const char rcsid[] = "$Id: inet_neta.c,v 1.3 2002/05/24 21:22:37 deraadt Exp $";
#else
-static const char rcsid[] = "$OpenBSD: inet_neta.c,v 1.2 1997/04/05 21:13:12 millert Exp $";
+static const char rcsid[] = "$OpenBSD: inet_neta.c,v 1.3 2002/05/24 21:22:37 deraadt Exp $";
#endif
#endif
@@ -73,7 +73,7 @@ inet_neta(src, dst, size)
if (dst == odst) {
if (size < sizeof "0.0.0.0")
goto emsgsize;
- strcpy(dst, "0.0.0.0");
+ strlcpy(dst, "0.0.0.0", size);
}
return (odst);
diff --git a/lib/libc/net/inet_ntop.c b/lib/libc/net/inet_ntop.c
index 00b8f6b22e6..212c0396b27 100644
--- a/lib/libc/net/inet_ntop.c
+++ b/lib/libc/net/inet_ntop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inet_ntop.c,v 1.2 2002/02/16 21:27:23 millert Exp $ */
+/* $OpenBSD: inet_ntop.c,v 1.3 2002/05/24 21:22:37 deraadt Exp $ */
/* Copyright (c) 1996 by Internet Software Consortium.
*
@@ -20,7 +20,7 @@
#if 0
static char rcsid[] = "$From: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.2 2002/02/16 21:27:23 millert Exp $";
+static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.3 2002/05/24 21:22:37 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -89,11 +89,11 @@ inet_ntop4(src, dst, size)
static const char fmt[] = "%u.%u.%u.%u";
char tmp[sizeof "255.255.255.255"];
- if (sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) {
+ if (snprintf(tmp, size, fmt, src[0], src[1], src[2], src[3]) >= size) {
errno = ENOSPC;
return (NULL);
}
- strcpy(dst, tmp);
+ strlcpy(dst, tmp, size);
return (dst);
}
@@ -189,6 +189,6 @@ inet_ntop6(src, dst, size)
errno = ENOSPC;
return (NULL);
}
- strcpy(dst, tmp);
+ strlcpy(dst, tmp, size);
return (dst);
}
diff --git a/lib/libc/net/ipx_ntoa.c b/lib/libc/net/ipx_ntoa.c
index 1dcfe7181b8..598c94d5995 100644
--- a/lib/libc/net/ipx_ntoa.c
+++ b/lib/libc/net/ipx_ntoa.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: ipx_ntoa.c,v 1.2 1996/08/19 08:29:20 tholo Exp $";
+static char rcsid[] = "$OpenBSD: ipx_ntoa.c,v 1.3 2002/05/24 21:22:37 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -45,7 +45,7 @@ ipx_ntoa(addr)
{
static char obuf[] = "xxxx.xx:xx:xx:xx:xx:xx.uuuuu";
- sprintf(obuf, "%8xH.%02x:%02x:%02x:%02x:%02x:%02x.%u",
+ snprintf(obuf, sizeof obuf, "%8xH.%02x:%02x:%02x:%02x:%02x:%02x.%u",
ntohl(addr.ipx_net.l_net),
addr.ipx_host.c_host[0],
addr.ipx_host.c_host[1],
diff --git a/lib/libc/net/ns_ntoa.c b/lib/libc/net/ns_ntoa.c
index 130ccd388bf..3c82bc3cee8 100644
--- a/lib/libc/net/ns_ntoa.c
+++ b/lib/libc/net/ns_ntoa.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.8 2002/02/16 21:27:23 millert Exp $";
+static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.9 2002/05/24 21:22:37 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -54,7 +54,7 @@ ns_ntoa(addr)
u_char *uplim = up + 6;
net.net_e = addr.x_net;
- sprintf(obuf, "%x", ntohl(net.long_e));
+ snprintf(obuf, sizeof obuf, "%x", ntohl(net.long_e));
cp = spectHex(obuf);
cp2 = cp + 1;
while (*up==0 && up < uplim) up++;
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c
index d6814676f4e..be68c599d8c 100644
--- a/lib/libc/net/rcmd.c
+++ b/lib/libc/net/rcmd.c
@@ -34,7 +34,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: rcmd.c,v 1.42 2002/05/22 04:31:14 deraadt Exp $";
+static char *rcsid = "$OpenBSD: rcmd.c,v 1.43 2002/05/24 21:22:37 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -407,8 +407,7 @@ again:
first = 0;
if ((pwd = getpwnam(luser)) == NULL)
return (-1);
- (void)strcpy(pbuf, pwd->pw_dir);
- (void)strcat(pbuf, "/.rhosts");
+ snprintf(pbuf, sizeof pbuf, "%s/.rhosts", pwd->pw_dir);
/*
* Change effective uid while opening .rhosts. If root and
diff --git a/lib/libc/net/res_debug.c b/lib/libc/net/res_debug.c
index 54be69cef74..75d70e86b6f 100644
--- a/lib/libc/net/res_debug.c
+++ b/lib/libc/net/res_debug.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_debug.c,v 1.11 2001/06/11 10:05:59 itojun Exp $ */
+/* $OpenBSD: res_debug.c,v 1.12 2002/05/24 21:22:37 deraadt Exp $ */
/*
* ++Copyright++ 1985, 1990, 1993
@@ -82,7 +82,7 @@
static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: res_debug.c,v 1.11 2001/06/11 10:05:59 itojun Exp $";
+static char rcsid[] = "$OpenBSD: res_debug.c,v 1.12 2002/05/24 21:22:37 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -159,7 +159,9 @@ dewks(wks)
case 161: return "snmp";
case 162: return "snmp-trap";
case 170: return "print-srv";
- default: (void) sprintf(nbuf, "%d", wks); return (nbuf);
+ default:
+ (void) snprintf(nbuf, sizeof nbuf, "%d", wks);
+ return (nbuf);
}
}
@@ -183,7 +185,9 @@ deproto(protonum)
case 12: return "pup";
case 16: return "chaos";
case 17: return "udp";
- default: (void) sprintf(nbuf, "%d", protonum); return (nbuf);
+ default:
+ (void) snprintf(nbuf, sizeof nbuf, "%d", protonum);
+ return (nbuf);
}
}
@@ -436,7 +440,7 @@ __p_fqnname(cp, msg, msglen, name, namelen)
if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
return (NULL);
- newlen = strlen (name);
+ newlen = strlen(name);
if (newlen == 0 || name[newlen - 1] != '.') {
if (newlen+1 >= namelen) /* Lack space for final dot */
return (NULL);
@@ -958,7 +962,7 @@ __sym_ntos(syms, number, success)
}
}
- sprintf (unname, "%d", number);
+ snprintf(unname, sizeof unname, "%d", number);
if (success)
*success = 0;
return (unname);
@@ -980,7 +984,7 @@ __sym_ntop(syms, number, success)
return (syms->humanname);
}
}
- sprintf(unname, "%d", number);
+ snprintf(unname, sizeof unname, "%d", number);
if (success)
*success = 0;
return (unname);
@@ -1030,8 +1034,9 @@ __p_option(option)
case RES_INSECURE2: return "insecure2";
case RES_USE_INET6: return "inet6";
case RES_USE_EDNS0: return "edns0";
- default: sprintf(nbuf, "?0x%lx?", (u_long)option);
- return (nbuf);
+ default:
+ snprintf(nbuf, sizeof nbuf, "?0x%lx?", (u_long)option);
+ return (nbuf);
}
}
@@ -1047,7 +1052,7 @@ p_time(value)
register char *p;
if (value == 0) {
- strcpy(nbuf, "0 secs");
+ strlcpy(nbuf, "0 secs", sizeof nbuf);
return (nbuf);
}
@@ -1109,7 +1114,7 @@ precsize_ntoa(prec)
val = mantissa * poweroften[exponent];
- (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
+ (void) snprintf(retbuf, sizeof retbuf, "%ld.%.2ld", val/100, val%100);
return (retbuf);
}
@@ -1513,7 +1518,7 @@ __p_secstodate (secs)
time = gmtime(&clock);
time->tm_year += 1900;
time->tm_mon += 1;
- sprintf(output, "%04d%02d%02d%02d%02d%02d",
+ snprintf(output, sizeof output, "%04d%02d%02d%02d%02d%02d",
time->tm_year, time->tm_mon, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec);
return (output);
diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c
index 24c07491a9a..53837815c38 100644
--- a/lib/libc/net/res_query.c
+++ b/lib/libc/net/res_query.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_query.c,v 1.17 2002/02/16 21:27:23 millert Exp $ */
+/* $OpenBSD: res_query.c,v 1.18 2002/05/24 21:22:37 deraadt Exp $ */
/*
* ++Copyright++ 1988, 1993
@@ -60,7 +60,7 @@
static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: res_query.c,v 1.17 2002/02/16 21:27:23 millert Exp $";
+static char rcsid[] = "$OpenBSD: res_query.c,v 1.18 2002/05/24 21:22:37 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -351,7 +351,8 @@ res_querydomain(name, domain, class, type, answer, anslen)
} else
longname = name;
} else
- sprintf(nbuf, "%.*s.%.*s", MAXDNAME, name, MAXDNAME, domain);
+ snprintf(nbuf, sizeof nbuf, "%.*s.%.*s",
+ MAXDNAME, name, MAXDNAME, domain);
return (res_query(longname, class, type, answer, anslen));
}