use strlcpy

This commit is contained in:
itojun 2002-11-16 04:34:13 +00:00
parent 8fcb6ec6c6
commit 9593086444
8 changed files with 35 additions and 47 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: klogin.c,v 1.16 2000/08/02 05:58:35 thorpej Exp $ */
/* $NetBSD: klogin.c,v 1.17 2002/11/16 04:38:45 itojun Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)klogin.c 8.3 (Berkeley) 4/2/94";
#endif
__RCSID("$NetBSD: klogin.c,v 1.16 2000/08/02 05:58:35 thorpej Exp $");
__RCSID("$NetBSD: klogin.c,v 1.17 2002/11/16 04:38:45 itojun Exp $");
#endif /* not lint */
#ifdef KERBEROS
@ -154,8 +154,7 @@ klogin(pw, instance, localhost, password)
if (chown(TKT_FILE, pw->pw_uid, pw->pw_gid) < 0)
syslog(LOG_ERR, "chown tkfile (%s): %m", TKT_FILE);
(void)strncpy(savehost, krb_get_phost(localhost), sizeof(savehost));
savehost[sizeof(savehost)-1] = NULL;
(void)strlcpy(savehost, krb_get_phost(localhost), sizeof(savehost));
/*
* if the "VERIFY_SERVICE" doesn't exist in the KDC for this host,
@ -270,9 +269,8 @@ out:
/*
* handle the shared memory case
*/
/* 5 == 4 (".shm") + 1 */
(void)strncpy(shmidname, file, sizeof(shmidname) - 5);
(void)strcat(shmidname, ".shm"); /* XXX strcat is safe */
(void)strlcpy(shmidname, file, sizeof(shmidname));
(void)strlcat(shmidname, ".shm", sizeof(shmidname));
if (krb_shm_dest(shmidname) != KSUCCESS)
return;
#endif /* TKT_SHMEM */

View File

@ -1,4 +1,4 @@
/* $NetBSD: login.c,v 1.70 2002/09/25 03:45:32 itojun Exp $ */
/* $NetBSD: login.c,v 1.71 2002/11/16 04:38:45 itojun Exp $ */
/*-
* Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994
@ -44,7 +44,7 @@ __COPYRIGHT(
#if 0
static char sccsid[] = "@(#)login.c 8.4 (Berkeley) 4/2/94";
#endif
__RCSID("$NetBSD: login.c,v 1.70 2002/09/25 03:45:32 itojun Exp $");
__RCSID("$NetBSD: login.c,v 1.71 2002/11/16 04:38:45 itojun Exp $");
#endif /* not lint */
/*
@ -377,8 +377,7 @@ main(argc, argv)
badlogin(tbuf);
failures = 0;
}
(void)strncpy(tbuf, username, sizeof(tbuf) - 1);
tbuf[sizeof(tbuf) - 1] = '\0';
(void)strlcpy(tbuf, username, sizeof(tbuf));
if ((pwd = getpwnam(username)) != NULL)
salt = pwd->pw_passwd;
@ -672,7 +671,7 @@ main(argc, argv)
tt = login_getcapstr(lc, "term", NULL, NULL);
#endif
/* unknown term -> "su" */
(void)strncpy(term, tt != NULL ? tt : "su", sizeof(term));
(void)strlcpy(term, tt != NULL ? tt : "su", sizeof(term));
}
(void)setenv("TERM", term, 0);
(void)setenv("LOGNAME", pwd->pw_name, 1);
@ -745,8 +744,8 @@ main(argc, argv)
(void)signal(SIGTSTP, SIG_IGN);
tbuf[0] = '-';
(void)strncpy(tbuf + 1, (p = strrchr(pwd->pw_shell, '/')) ?
p + 1 : pwd->pw_shell, sizeof(tbuf) - 2);
(void)strlcpy(tbuf + 1, (p = strrchr(pwd->pw_shell, '/')) ?
p + 1 : pwd->pw_shell, sizeof(tbuf) - 1);
/* Wait to change password until we're unprivileged */
if (need_chpass) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: local_passwd.c,v 1.24 2001/08/18 19:42:40 ad Exp $ */
/* $NetBSD: local_passwd.c,v 1.25 2002/11/16 04:41:50 itojun Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)local_passwd.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: local_passwd.c,v 1.24 2001/08/18 19:42:40 ad Exp $");
__RCSID("$NetBSD: local_passwd.c,v 1.25 2002/11/16 04:41:50 itojun Exp $");
#endif
#endif /* not lint */
@ -106,8 +106,7 @@ getnewpasswd(pw, min_pw_len)
"suggested.\n");
continue;
}
(void)strncpy(buf, p, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
(void)strlcpy(buf, p, sizeof(buf));
if (!strcmp(buf, getpass("Retype new password:")))
break;
(void)printf("Mismatch; try again, EOF to quit.\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: pwd_gensalt.c,v 1.8 2002/10/01 20:48:58 provos Exp $ */
/* $NetBSD: pwd_gensalt.c,v 1.9 2002/11/16 04:41:50 itojun Exp $ */
/*
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: pwd_gensalt.c,v 1.8 2002/10/01 20:48:58 provos Exp $");
__RCSID("$NetBSD: pwd_gensalt.c,v 1.9 2002/11/16 04:41:50 itojun Exp $");
#endif /* not lint */
#include <sys/syslimits.h>
@ -122,8 +122,7 @@ pwd_gensalt(char *salt, int max, struct passwd *pwd, char type)
rounds = atoi(next);
if (rounds < 4)
rounds = 4;
strncpy(salt, bcrypt_gensalt(rounds), max - 1);
salt[max - 1] = 0;
strlcpy(salt, bcrypt_gensalt(rounds), max);
} else {
strcpy(salt, ":");
warnx("Unknown option %s.", now);

View File

@ -1,4 +1,4 @@
/* $NetBSD: yp_passwd.c,v 1.24 2001/02/13 00:14:58 cgd Exp $ */
/* $NetBSD: yp_passwd.c,v 1.25 2002/11/16 04:41:50 itojun Exp $ */
/*
* Copyright (c) 1988, 1990, 1993, 1994
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)local_passwd.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: yp_passwd.c,v 1.24 2001/02/13 00:14:58 cgd Exp $");
__RCSID("$NetBSD: yp_passwd.c,v 1.25 2002/11/16 04:41:50 itojun Exp $");
#endif
#endif /* not lint */
@ -277,7 +277,7 @@ getnewpasswd(pw, old_pass)
"suggested.\n");
continue;
}
(void)strncpy(buf, p, sizeof(buf) - 1);
(void)strlcpy(buf, p, sizeof(buf));
if (!strcmp(buf, getpass("Retype new password:")))
break;
(void)printf("Mismatch; try again, EOF to quit.\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: rlogin.c,v 1.26 2002/06/14 00:55:48 wiz Exp $ */
/* $NetBSD: rlogin.c,v 1.27 2002/11/16 04:42:26 itojun Exp $ */
/*
* Copyright (c) 1983, 1990, 1993
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)rlogin.c 8.4 (Berkeley) 4/29/95";
#else
__RCSID("$NetBSD: rlogin.c,v 1.26 2002/06/14 00:55:48 wiz Exp $");
__RCSID("$NetBSD: rlogin.c,v 1.27 2002/11/16 04:42:26 itojun Exp $");
#endif
#endif /* not lint */
@ -277,10 +277,8 @@ main(int argc, char *argv[])
if (sp == NULL)
errx(1, "login/tcp: unknown service.");
if ((p = getenv("TERM")) != NULL) {
(void)strncpy(term, p, sizeof(term) - 1);
term[sizeof(term) - 1] = '\0';
}
if ((p = getenv("TERM")) != NULL)
(void)strlcpy(term, p, sizeof(term));
len = strlen(term);
if (len < (sizeof(term) - 1) && tcgetattr(0, &tty) == 0) {
/* start at 2 to include the / */

View File

@ -1,4 +1,4 @@
/* $NetBSD: crontab.c,v 1.15 1999/05/29 18:43:40 christos Exp $ */
/* $NetBSD: crontab.c,v 1.16 2002/11/16 04:34:13 itojun Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@ -22,7 +22,7 @@
#if 0
static char rcsid[] = "Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp";
#else
__RCSID("$NetBSD: crontab.c,v 1.15 1999/05/29 18:43:40 christos Exp $");
__RCSID("$NetBSD: crontab.c,v 1.16 2002/11/16 04:34:13 itojun Exp $");
#endif
#endif
@ -159,10 +159,8 @@ parse_args(argc, argv)
fprintf(stderr, "bailing out.\n");
exit(ERROR_EXIT);
}
strncpy(User, pw->pw_name, sizeof(User) - 1);
User[sizeof(User) - 1] = '\0';
strncpy(RealUser, User, sizeof(RealUser) - 1);
RealUser[sizeof(RealUser) - 1] = '\0';
strlcpy(User, pw->pw_name, sizeof(User));
strlcpy(RealUser, User, sizeof(RealUser));
Filename[0] = '\0';
Option = opt_unknown;
while (-1 != (argch = getopt(argc, argv, "u:lerx:"))) {
@ -184,8 +182,7 @@ parse_args(argc, argv)
ProgramName, optarg);
exit(ERROR_EXIT);
}
(void) strncpy(User, optarg, sizeof(User) - 1);
User[sizeof(User) - 1] = '\0';
(void) strlcpy(User, optarg, sizeof(User));
break;
case 'l':
if (Option != opt_unknown)
@ -216,9 +213,8 @@ parse_args(argc, argv)
} else {
if (argv[optind] != NULL) {
Option = opt_replace;
(void) strncpy (Filename, argv[optind],
sizeof(Filename) - 1);
Filename[sizeof(Filename) - 1] = '\0';
(void) strlcpy(Filename, argv[optind],
sizeof(Filename));
} else {
usage("file name must be specified for replace");
}
@ -571,7 +567,7 @@ replace_cmd() {
fprintf(tmp, "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n");
fprintf(tmp, "# (%s installed on %-24.24s)\n", Filename, ctime(&now));
fprintf(tmp, "# (Cron version -- %s)\n",
"$NetBSD: crontab.c,v 1.15 1999/05/29 18:43:40 christos Exp $");
"$NetBSD: crontab.c,v 1.16 2002/11/16 04:34:13 itojun Exp $");
/* copy the crontab to the tmp
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: database.c,v 1.5 2002/08/03 02:03:00 itojun Exp $ */
/* $NetBSD: database.c,v 1.6 2002/11/16 04:34:13 itojun Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@ -22,7 +22,7 @@
#if 0
static char rcsid[] = "Id: database.c,v 2.8 1994/01/15 20:43:43 vixie Exp";
#else
__RCSID("$NetBSD: database.c,v 1.5 2002/08/03 02:03:00 itojun Exp $");
__RCSID("$NetBSD: database.c,v 1.6 2002/11/16 04:34:13 itojun Exp $");
#endif
#endif
@ -118,8 +118,7 @@ load_database(old_db)
if (dp->d_name[0] == '.')
continue;
(void) strncpy(fname, dp->d_name, sizeof(fname) - 1);
fname[sizeof(fname) - 1] = '\0';
(void) strlcpy(fname, dp->d_name, sizeof(fname));
snprintf(tabname, sizeof(tabname), CRON_TAB(fname));
process_crontab(fname, fname, tabname,