summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoritojun <itojun@NetBSD.org>2003-07-12 13:23:55 +0000
committeritojun <itojun@NetBSD.org>2003-07-12 13:23:55 +0000
commit032ed69f9a47a49c09dd24ffb4e5dfa09cd030b8 (patch)
tree7a1ccda107e800453dafc3f5041e5ada3118f8af
parenta7f5ddbf6454871154c3109480b03fd50760ff2d (diff)
strlcpy
-rw-r--r--bin/csh/sem.c10
-rw-r--r--bin/date/netdate.c6
-rw-r--r--usr.bin/finger/util.c9
-rw-r--r--usr.bin/ftp/fetch.c9
-rw-r--r--usr.bin/ipcs/ipcs.c9
-rw-r--r--usr.bin/telnet/authenc.c6
-rw-r--r--usr.bin/telnet/commands.c20
-rw-r--r--usr.bin/telnet/main.c6
8 files changed, 33 insertions, 42 deletions
diff --git a/bin/csh/sem.c b/bin/csh/sem.c
index 04710b98ac9..1f6576e0f2c 100644
--- a/bin/csh/sem.c
+++ b/bin/csh/sem.c
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.c,v 1.21 2003/01/16 09:38:41 kleink Exp $ */
+/* $NetBSD: sem.c,v 1.22 2003/07/12 13:24:52 itojun Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)sem.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: sem.c,v 1.21 2003/01/16 09:38:41 kleink Exp $");
+__RCSID("$NetBSD: sem.c,v 1.22 2003/07/12 13:24:52 itojun Exp $");
#endif
#endif /* not lint */
@@ -542,8 +542,7 @@ doio(struct command *t, int *pipein, int *pipeout)
(void)dcopy(SHOUT, 1);
(void)dcopy(SHERR, 2);
cp = splicepipe(t, t->t_dlef);
- (void)strncpy(tmp, short2str(cp), MAXPATHLEN);
- tmp[MAXPATHLEN] = '\0';
+ (void)strlcpy(tmp, short2str(cp), sizeof(tmp));
xfree((ptr_t) cp);
if ((fd = open(tmp, O_RDONLY)) < 0) {
stderror(ERR_SYSTEM, tmp, strerror(errno));
@@ -571,8 +570,7 @@ doio(struct command *t, int *pipein, int *pipeout)
char tmp[MAXPATHLEN+1];
cp = splicepipe(t, t->t_drit);
- (void)strncpy(tmp, short2str(cp), MAXPATHLEN);
- tmp[MAXPATHLEN] = '\0';
+ (void)strlcpy(tmp, short2str(cp), sizeof(tmp));
xfree((ptr_t) cp);
/*
* so > /dev/std{out,err} work
diff --git a/bin/date/netdate.c b/bin/date/netdate.c
index c3f8ca74d82..b07f01f6b8f 100644
--- a/bin/date/netdate.c
+++ b/bin/date/netdate.c
@@ -1,4 +1,4 @@
-/* $NetBSD: netdate.c,v 1.22 2002/09/21 18:15:57 mycroft Exp $ */
+/* $NetBSD: netdate.c,v 1.23 2003/07/12 13:23:55 itojun Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)netdate.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: netdate.c,v 1.22 2002/09/21 18:15:57 mycroft Exp $");
+__RCSID("$NetBSD: netdate.c,v 1.23 2003/07/12 13:23:55 itojun Exp $");
#endif
#endif /* not lint */
@@ -131,7 +131,7 @@ netsettime(time_t tval)
goto bad;
}
hostname[sizeof(hostname) - 1] = '\0';
- (void)strncpy(msg.tsp_name, hostname, sizeof(hostname));
+ (void)strlcpy(msg.tsp_name, hostname, sizeof(msg.tsp_name));
msg.tsp_seq = htons((u_short)0);
msg.tsp_time.tv_sec = htonl((u_long)tval);
msg.tsp_time.tv_usec = htonl((u_long)0);
diff --git a/usr.bin/finger/util.c b/usr.bin/finger/util.c
index bbde43b2746..4e151cfad06 100644
--- a/usr.bin/finger/util.c
+++ b/usr.bin/finger/util.c
@@ -1,4 +1,4 @@
-/* $NetBSD: util.c,v 1.19 2003/01/20 05:30:11 simonb Exp $ */
+/* $NetBSD: util.c,v 1.20 2003/07/12 13:28:10 itojun Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: util.c,v 1.19 2003/01/20 05:30:11 simonb Exp $");
+__RCSID("$NetBSD: util.c,v 1.20 2003/07/12 13:28:10 itojun Exp $");
#endif
#endif /* not lint */
@@ -82,7 +82,7 @@ match(pw, user)
if (!strcasecmp(pw->pw_name, user))
return(1);
- (void)strncpy(bp = tbuf, pw->pw_gecos, sizeof(tbuf));
+ (void)strlcpy(bp = tbuf, pw->pw_gecos, sizeof(tbuf));
/* Ampersands get replaced by the login name. */
if (!(p = strsep(&bp, ",")))
@@ -365,8 +365,7 @@ userinfo(pn, pw)
pn->dir = strdup(pw->pw_dir);
pn->shell = strdup(pw->pw_shell);
- (void)strncpy(bp = tbuf, pw->pw_gecos, sizeof(tbuf));
- tbuf[sizeof(tbuf) - 1] = '\0';
+ (void)strlcpy(bp = tbuf, pw->pw_gecos, sizeof(tbuf));
/* ampersands get replaced by the login name */
if (!(p = strsep(&bp, ",")))
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index acd1edc8df6..3d56a3bee8f 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.141 2003/05/14 14:31:00 wiz Exp $ */
+/* $NetBSD: fetch.c,v 1.142 2003/07/12 13:30:04 itojun Exp $ */
/*-
* Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.141 2003/05/14 14:31:00 wiz Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.142 2003/07/12 13:30:04 itojun Exp $");
#endif /* not lint */
/*
@@ -665,9 +665,8 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
*/
ai_unmapped(res);
if (getnameinfo(res->ai_addr, res->ai_addrlen,
- hbuf, sizeof(hbuf), NULL, 0,
- NI_NUMERICHOST) != 0)
- strncpy(hbuf, "invalid", sizeof(hbuf));
+ hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0)
+ strlcpy(hbuf, "invalid", sizeof(hbuf));
if (verbose && res != res0)
fprintf(ttyout, "Trying %s...\n", hbuf);
diff --git a/usr.bin/ipcs/ipcs.c b/usr.bin/ipcs/ipcs.c
index 5092c6704c3..69f83df6aa0 100644
--- a/usr.bin/ipcs/ipcs.c
+++ b/usr.bin/ipcs/ipcs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ipcs.c,v 1.29 2003/04/07 01:42:37 simonb Exp $ */
+/* $NetBSD: ipcs.c,v 1.30 2003/07/12 13:29:15 itojun Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -133,10 +133,9 @@ cvt_time(time_t t, char *buf, size_t buflen)
{
struct tm *tm;
- if (t == 0) {
- (void)strncpy(buf, "no-entry", buflen - 1);
- buf[buflen - 1] = '\0';
- } else {
+ if (t == 0)
+ (void)strlcpy(buf, "no-entry", buflen);
+ else {
tm = localtime(&t);
(void)snprintf(buf, buflen, "%2d:%02d:%02d",
tm->tm_hour, tm->tm_min, tm->tm_sec);
diff --git a/usr.bin/telnet/authenc.c b/usr.bin/telnet/authenc.c
index 1345ab085f9..fe849a313b8 100644
--- a/usr.bin/telnet/authenc.c
+++ b/usr.bin/telnet/authenc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: authenc.c,v 1.10 2003/06/18 20:51:00 christos Exp $ */
+/* $NetBSD: authenc.c,v 1.11 2003/07/12 13:33:08 itojun Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: authenc.c,v 1.10 2003/06/18 20:51:00 christos Exp $");
+__RCSID("$NetBSD: authenc.c,v 1.11 2003/07/12 13:33:08 itojun Exp $");
#endif
#endif /* not lint */
@@ -102,7 +102,7 @@ telnet_gets(char *prompt, char *result, int length, int echo)
printf("%s", prompt);
res = fgets(result, length, stdin);
} else if ((res = getpass(prompt)) != NULL) {
- strncpy(result, res, length);
+ strlcpy(result, res, length);
res = result;
}
TerminalNewMode(om);
diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c
index 66a74f69a0c..d7227d253a2 100644
--- a/usr.bin/telnet/commands.c
+++ b/usr.bin/telnet/commands.c
@@ -1,4 +1,4 @@
-/* $NetBSD: commands.c,v 1.51 2003/06/18 20:51:00 christos Exp $ */
+/* $NetBSD: commands.c,v 1.52 2003/07/12 13:33:08 itojun Exp $ */
/*
* Copyright (C) 1997 and 1998 WIDE Project.
@@ -67,7 +67,7 @@
#if 0
static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
#else
-__RCSID("$NetBSD: commands.c,v 1.51 2003/06/18 20:51:00 christos Exp $");
+__RCSID("$NetBSD: commands.c,v 1.52 2003/07/12 13:33:08 itojun Exp $");
#endif
#endif /* not lint */
@@ -2343,10 +2343,8 @@ tn(int argc, char *argv[])
getnameinfo(res0->ai_addr, res0->ai_addrlen,
_hostname, sizeof(_hostname), NULL, 0, NI_NAMEREQD) == 0)
; /* okay */
- else {
- strncpy(_hostname, hostname, sizeof(_hostname) - 1);
- _hostname[sizeof(_hostname) - 1] = '\0';
- }
+ else
+ strlcpy(_hostname, hostname, sizeof(_hostname));
} else {
/* FQDN - try again with forward DNS lookup */
memset(&hints, 0, sizeof(hints));
@@ -2362,12 +2360,10 @@ tn(int argc, char *argv[])
fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
return 0;
}
- if (res0->ai_canonname) {
- (void) strncpy(_hostname, res0->ai_canonname,
- sizeof(_hostname) - 1);
- } else
- (void) strncpy(_hostname, hostname, sizeof(_hostname) - 1);
- _hostname[sizeof(_hostname) - 1] = '\0';
+ if (res0->ai_canonname)
+ (void)strlcpy(_hostname, res0->ai_canonname, sizeof(_hostname));
+ else
+ (void)strlcpy(_hostname, hostname, sizeof(_hostname));
}
hostname = _hostname;
diff --git a/usr.bin/telnet/main.c b/usr.bin/telnet/main.c
index 1ac015b26cd..23b105c1f94 100644
--- a/usr.bin/telnet/main.c
+++ b/usr.bin/telnet/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.18 2003/06/18 20:51:00 christos Exp $ */
+/* $NetBSD: main.c,v 1.19 2003/07/12 13:33:08 itojun Exp $ */
/*
* Copyright (c) 1988, 1990, 1993
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
#else
-__RCSID("$NetBSD: main.c,v 1.18 2003/06/18 20:51:00 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.19 2003/07/12 13:33:08 itojun Exp $");
#endif
#endif /* not lint */
@@ -264,7 +264,7 @@ main(int argc, char *argv[])
{
extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
dest_realm = dst_realm_buf;
- (void)strncpy(dest_realm, optarg, dst_realm_sz);
+ (void)strlcpy(dest_realm, optarg, dst_realm_sz);
}
#else
fprintf(stderr,