summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1996-08-27 10:22:04 +0000
committerderaadt <deraadt@openbsd.org>1996-08-27 10:22:04 +0000
commita1998c9de728d65e40ee6dde119240c72d377cc9 (patch)
tree88861885150bfb3b160ea07f9cba4d38a849ee3c
parentstrncpy correctly (diff)
downloadwireguard-openbsd-a1998c9de728d65e40ee6dde119240c72d377cc9.tar.xz
wireguard-openbsd-a1998c9de728d65e40ee6dde119240c72d377cc9.zip
strncpy correctly
-rw-r--r--libexec/comsat/comsat.c4
-rw-r--r--libexec/rlogind/rlogind.c7
-rw-r--r--libexec/rpc.lockd/procs.c2
-rw-r--r--libexec/telnetd/telnetd.c16
-rw-r--r--libexec/uucpd/uucpd.c7
-rw-r--r--usr.sbin/rpc.lockd/procs.c2
6 files changed, 22 insertions, 16 deletions
diff --git a/libexec/comsat/comsat.c b/libexec/comsat/comsat.c
index 25ad6803ae8..0b4e41d3273 100644
--- a/libexec/comsat/comsat.c
+++ b/libexec/comsat/comsat.c
@@ -39,7 +39,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)comsat.c 8.1 (Berkeley) 6/4/93";*/
-static char rcsid[] = "$Id: comsat.c,v 1.1.1.1 1995/10/18 08:43:15 deraadt Exp $";
+static char rcsid[] = "$Id: comsat.c,v 1.2 1996/08/27 10:22:04 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -221,7 +221,7 @@ notify(utp, offset)
(void)tcgetattr(fileno(tp), &ttybuf);
cr = (ttybuf.c_oflag & ONLCR) && (ttybuf.c_oflag & OPOST) ?
"\n" : "\n\r";
- (void)strncpy(name, utp->ut_name, sizeof(utp->ut_name));
+ (void)strncpy(name, utp->ut_name, sizeof(name) - 1);
name[sizeof(name) - 1] = '\0';
(void)fprintf(tp, "%s\007New mail for %s@%.*s\007 has arrived:%s----%s",
cr, name, (int)sizeof(hostname), hostname, cr, cr);
diff --git a/libexec/rlogind/rlogind.c b/libexec/rlogind/rlogind.c
index cf016a9397e..8e5ba9348c5 100644
--- a/libexec/rlogind/rlogind.c
+++ b/libexec/rlogind/rlogind.c
@@ -39,7 +39,7 @@ static char copyright[] =
#ifndef lint
/* from: static char sccsid[] = "@(#)rlogind.c 8.1 (Berkeley) 6/4/93"; */
-static char *rcsid = "$Id: rlogind.c,v 1.8 1996/08/02 10:13:35 deraadt Exp $";
+static char *rcsid = "$Id: rlogind.c,v 1.9 1996/08/27 10:26:59 deraadt Exp $";
#endif /* not lint */
/*
@@ -216,7 +216,7 @@ doit(f, fromp)
hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof(struct in_addr),
fromp->sin_family);
if (hp) {
- strncpy(hostname, hp->h_name, sizeof hostname);
+ strncpy(hostname, hp->h_name, sizeof(hostname)-1);
if (check_all) {
hp = gethostbyname(hostname);
if (hp) {
@@ -233,7 +233,8 @@ doit(f, fromp)
}
/* aha, the DNS looks spoofed */
if (hp == NULL || good == 0)
- strncpy(hostname, inet_ntoa(fromp->sin_addr), sizeof hostname);
+ strncpy(hostname, inet_ntoa(fromp->sin_addr), sizeof(hostname)-1);
+ hostname[sizeof(hostname)-1] = '\0';
#ifdef KERBEROS
diff --git a/libexec/rpc.lockd/procs.c b/libexec/rpc.lockd/procs.c
index 54e5f814ceb..91a2a220cfe 100644
--- a/libexec/rpc.lockd/procs.c
+++ b/libexec/rpc.lockd/procs.c
@@ -64,7 +64,7 @@ static void log_from_addr(char *fun_name, struct svc_req *req)
host = gethostbyaddr((char *)&(addr->sin_addr), addr->sin_len, AF_INET);
if (host)
{
- strncpy(hostname_buf, host->h_name, sizeof(hostname_buf));
+ strncpy(hostname_buf, host->h_name, sizeof(hostname_buf) -1);
hostname_buf[sizeof(hostname_buf) -1] = '\0';
}
else /* No hostname available - print raw address */
diff --git a/libexec/telnetd/telnetd.c b/libexec/telnetd/telnetd.c
index f184628f446..a86a0aae412 100644
--- a/libexec/telnetd/telnetd.c
+++ b/libexec/telnetd/telnetd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: telnetd.c,v 1.3 1996/04/23 03:03:55 deraadt Exp $ */
+/* $OpenBSD: telnetd.c,v 1.4 1996/08/27 10:25:28 deraadt Exp $ */
/* $NetBSD: telnetd.c,v 1.6 1996/03/20 04:25:57 tls Exp $ */
/*
@@ -45,7 +45,7 @@ static char copyright[] =
static char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
static char rcsid[] = "$NetBSD: telnetd.c,v 1.5 1996/02/28 20:38:23 thorpej Exp $";
#else
-static char rcsid[] = "$OpenBSD: telnetd.c,v 1.3 1996/04/23 03:03:55 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: telnetd.c,v 1.4 1996/08/27 10:25:28 deraadt Exp $";
#endif
#endif /* not lint */
@@ -682,12 +682,14 @@ getterminaltype(name)
* we have to just go with what we (might) have already gotten.
*/
if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) {
- (void) strncpy(first, terminaltype, sizeof(first));
+ (void) strncpy(first, terminaltype, sizeof(first)-1);
+ first[sizeof(first)-1] = '\0';
for(;;) {
/*
* Save the unknown name, and request the next name.
*/
- (void) strncpy(last, terminaltype, sizeof(last));
+ (void) strncpy(last, terminaltype, sizeof(last)-1);
+ last[sizeof(last)-1] = '\0';
_gettermname();
if (terminaltypeok(terminaltype))
break;
@@ -705,8 +707,10 @@ getterminaltype(name)
* the start of the list.
*/
_gettermname();
- if (strncmp(first, terminaltype, sizeof(first)) != 0)
- (void) strncpy(terminaltype, first, sizeof(first));
+ if (strncmp(first, terminaltype, sizeof(first)) != 0) {
+ (void) strncpy(terminaltype, first, sizeof(terminaltype)-1);
+ terminaltype[sizeof(terminaltype)-1] = '\0';
+ }
break;
}
}
diff --git a/libexec/uucpd/uucpd.c b/libexec/uucpd/uucpd.c
index 98d3c67e3c0..8e14b5177c1 100644
--- a/libexec/uucpd/uucpd.c
+++ b/libexec/uucpd/uucpd.c
@@ -42,7 +42,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)uucpd.c 5.10 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: uucpd.c,v 1.2 1996/07/22 02:00:12 deraadt Exp $";
+static char rcsid[] = "$Id: uucpd.c,v 1.3 1996/08/27 10:23:00 deraadt Exp $";
#endif /* not lint */
/*
@@ -263,11 +263,12 @@ struct sockaddr_in *sin;
sizeof (struct in_addr), AF_INET);
if (hp) {
- strncpy(remotehost, hp->h_name, sizeof (remotehost));
+ strncpy(remotehost, hp->h_name, sizeof(remotehost)-1);
endhostent();
} else
strncpy(remotehost, inet_ntoa(sin->sin_addr),
- sizeof (remotehost));
+ sizeof(remotehost)-1);
+ remotehost[sizeof(remotehost)-1] = '\0';
wtmp = open(_PATH_WTMP, O_WRONLY|O_APPEND);
if (wtmp >= 0) {
/* hack, but must be unique and no tty line */
diff --git a/usr.sbin/rpc.lockd/procs.c b/usr.sbin/rpc.lockd/procs.c
index 54e5f814ceb..91a2a220cfe 100644
--- a/usr.sbin/rpc.lockd/procs.c
+++ b/usr.sbin/rpc.lockd/procs.c
@@ -64,7 +64,7 @@ static void log_from_addr(char *fun_name, struct svc_req *req)
host = gethostbyaddr((char *)&(addr->sin_addr), addr->sin_len, AF_INET);
if (host)
{
- strncpy(hostname_buf, host->h_name, sizeof(hostname_buf));
+ strncpy(hostname_buf, host->h_name, sizeof(hostname_buf) -1);
hostname_buf[sizeof(hostname_buf) -1] = '\0';
}
else /* No hostname available - print raw address */