diff --git a/dist/am-utils/amd/am_ops.c b/dist/am-utils/amd/am_ops.c index b3fa4b87a353..5e91ae649681 100644 --- a/dist/am-utils/amd/am_ops.c +++ b/dist/am-utils/amd/am_ops.c @@ -1,4 +1,4 @@ -/* $NetBSD: am_ops.c,v 1.1.1.6 2003/03/09 01:13:05 christos Exp $ */ +/* $NetBSD: am_ops.c,v 1.2 2003/07/14 17:20:13 itojun Exp $ */ /* * Copyright (c) 1997-2003 Erez Zadok @@ -332,8 +332,7 @@ merge_opts(const char *opts1, const char *opts2) tmpstr; tmpstr = strtok(NULL, ",")) { /* copy option to temp buffer */ - strncpy(oneopt, tmpstr, 80); - oneopt[79] = '\0'; + strlcpy(oneopt, tmpstr, sizeof(oneopt)); /* if option has a value such as rsize=1024, chop the value part */ if ((eq = haseq(oneopt))) *eq = '\0'; diff --git a/dist/am-utils/amd/amfs_host.c b/dist/am-utils/amd/amfs_host.c index 9a56e59eb892..d4b4ba19d607 100644 --- a/dist/am-utils/amd/amfs_host.c +++ b/dist/am-utils/amd/amfs_host.c @@ -1,4 +1,4 @@ -/* $NetBSD: amfs_host.c,v 1.1.1.6 2003/03/09 01:13:07 christos Exp $ */ +/* $NetBSD: amfs_host.c,v 1.2 2003/07/14 17:20:13 itojun Exp $ */ /* * Copyright (c) 1997-2003 Erez Zadok @@ -449,7 +449,7 @@ amfs_host_mount(am_node *am, mntfs *mf) * error code 0 at the end. If they all fail then return * the last error code. */ - strncpy(fs_name, mf->mf_info, sizeof(fs_name)); + strlcpy(fs_name, mf->mf_info, sizeof(fs_name)); if ((rfs_dir = strchr(fs_name, ':')) == (char *) 0) { plog(XLOG_FATAL, "amfs_host_mount: mf_info has no colon"); error = EINVAL; diff --git a/dist/am-utils/amd/ops_nfs.c b/dist/am-utils/amd/ops_nfs.c index f6cd4aa40a86..fcb2e82727a3 100644 --- a/dist/am-utils/amd/ops_nfs.c +++ b/dist/am-utils/amd/ops_nfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: ops_nfs.c,v 1.1.1.6 2003/03/09 01:13:16 christos Exp $ */ +/* $NetBSD: ops_nfs.c,v 1.2 2003/07/14 17:20:13 itojun Exp $ */ /* * Copyright (c) 1997-2003 Erez Zadok @@ -586,7 +586,7 @@ mount_nfs_fh(am_nfs_handle_t *fhp, char *mntdir, char *real_mntdir, char *fs_nam #ifdef MOUNT_TABLE_ON_FILE *colon = '\0'; #endif /* MOUNT_TABLE_ON_FILE */ - strncpy(host, fs_name, sizeof(host)); + strlcpy(host, fs_name, sizeof(host)); #ifdef MOUNT_TABLE_ON_FILE *colon = ':'; #endif /* MOUNT_TABLE_ON_FILE */ diff --git a/dist/am-utils/fixmount/fixmount.c b/dist/am-utils/fixmount/fixmount.c index 0f8271e4792c..d3c9dcff6bef 100644 --- a/dist/am-utils/fixmount/fixmount.c +++ b/dist/am-utils/fixmount/fixmount.c @@ -1,4 +1,4 @@ -/* $NetBSD: fixmount.c,v 1.1.1.6 2003/03/09 01:13:51 christos Exp $ */ +/* $NetBSD: fixmount.c,v 1.2 2003/07/14 17:20:15 itojun Exp $ */ /* * Copyright (c) 1997-2003 Erez Zadok @@ -121,7 +121,7 @@ is_same_host(char *name1, char *name2, struct in_addr addr2) } else if (!(he = gethostbyname(name1))) { return 0; } else { - strncpy(lasthost, name1, sizeof(lasthost) - 1); + strlcpy(lasthost, name1, sizeof(lasthost)); memcpy(&addr1, he->h_addr, sizeof(addr1)); return (addr1.s_addr == addr2.s_addr); } @@ -165,7 +165,7 @@ remove_mount(CLIENT *client, char *host, mountlist ml, int fixit) struct timeval tv; char *pathp = dir_path; - strncpy(dir_path, ml->ml_directory, sizeof(dir_path)); + strlcpy(dir_path, ml->ml_directory, sizeof(dir_path)); if (!fixit) { printf("%s: bogus mount %s:%s\n", host, ml->ml_hostname, ml->ml_directory); @@ -327,8 +327,7 @@ main(int argc, char *argv[]) break; case 'h': - strncpy(thishost, optarg, sizeof(thishost)); - thishost[sizeof(thishost) - 1] = '\0'; + strlcpy(thishost, optarg, sizeof(thishost)); break; case '?': @@ -368,8 +367,7 @@ main(int argc, char *argv[]) inet_ntoa(thisaddr)); exit(1); } - strncpy(thishost, he->h_name, sizeof(thishost)); - thishost[sizeof(thishost) - 1] = '\0'; + strlcpy(thishost, he->h_name, sizeof(thishost)); } else { thisaddr.s_addr = INADDR_NONE; } diff --git a/dist/am-utils/fsinfo/fsinfo.c b/dist/am-utils/fsinfo/fsinfo.c index 8050d4d889a9..c55d5025c347 100644 --- a/dist/am-utils/fsinfo/fsinfo.c +++ b/dist/am-utils/fsinfo/fsinfo.c @@ -1,4 +1,4 @@ -/* $NetBSD: fsinfo.c,v 1.7 2003/03/09 01:38:46 christos Exp $ */ +/* $NetBSD: fsinfo.c,v 1.8 2003/07/14 17:20:16 itojun Exp $ */ /* * Copyright (c) 1997-2003 Erez Zadok @@ -126,7 +126,7 @@ fsi_get_args(int c, char *v[]) break; case 'h': - strncpy(hostname, optarg, sizeof(hostname) - 1); + strlcpy(hostname, optarg, sizeof(hostname)); break; case 'e': diff --git a/dist/am-utils/libamu/xutil.c b/dist/am-utils/libamu/xutil.c index d7204790ba35..7e3b462c34c0 100644 --- a/dist/am-utils/libamu/xutil.c +++ b/dist/am-utils/libamu/xutil.c @@ -1,4 +1,4 @@ -/* $NetBSD: xutil.c,v 1.8 2003/03/29 10:56:52 darcy Exp $ */ +/* $NetBSD: xutil.c,v 1.9 2003/07/14 17:20:16 itojun Exp $ */ /* * Copyright (c) 1997-2003 Erez Zadok @@ -149,8 +149,7 @@ am_get_progname(void) void am_set_hostname(char *hn) { - strncpy(am_hostname, hn, MAXHOSTNAMELEN); - am_hostname[MAXHOSTNAMELEN] = '\0'; + strlcpy(am_hostname, hn, sizeof(am_hostname)); } @@ -499,7 +498,7 @@ real_plog(int lvl, const char *fmt, va_list vargs) switch (last_count) { case 0: /* never printed at all */ last_count = 1; - strncpy(last_msg, msg, 1024); + strlcpy(last_msg, msg, sizeof(last_msg)); last_lvl = lvl; show_time_host_and_name(lvl); /* mimic syslog header */ fwrite(msg, ptr - msg, 1, logfp); @@ -511,7 +510,7 @@ real_plog(int lvl, const char *fmt, va_list vargs) last_count++; } else { /* last msg printed once, new one differs */ /* last_count remains at 1 */ - strncpy(last_msg, msg, 1024); + strlcpy(last_msg, msg, sizeof(last_msg)); last_lvl = lvl; show_time_host_and_name(lvl); /* mimic syslog header */ fwrite(msg, ptr - msg, 1, logfp); @@ -538,7 +537,7 @@ real_plog(int lvl, const char *fmt, va_list vargs) show_time_host_and_name(last_lvl); sprintf(last_msg, "last message repeated %d times\n", last_count); fwrite(last_msg, strlen(last_msg), 1, logfp); - strncpy(last_msg, msg, 1024); + strlcpy(last_msg, msg, sizeof(last_msg)); last_count = 1; last_lvl = lvl; show_time_host_and_name(lvl); /* mimic syslog header */