2005-04-07 Erez Zadok <ezk@cs.sunysb.edu>
+ * libamu/xutil.c (am_set_hostname),
+ hlfsd/stubs.c (nfsproc_lookup_2_svc),
+ fsinfo/fsinfo.c (fsi_get_args),
+ fixmount/fixmount.c (is_same_host, remove_mount, main),
+ conf/mtab/mtab_isc3.c (mnt_dup, mtab_of),
+ conf/mount/mount_svr4.c (mount_svr4),
+ conf/mount/mount_linux.c (setup_loop_device),
+ conf/hn_dref/hn_dref_linux.h (NFS_HN_DREF),
+ conf/hn_dref/hn_dref_isc3.h (NFS_HN_DREF),
+ amd/opts.c (expand_op),
+ amd/ops_nfs.c (mount_nfs_fh),
+ amd/nfs_subr.c (fh_to_mp3, mp_to_fh),
+ amd/amfs_host.c (amfs_host_mount),
+ amd/am_ops.c (merge_opts):
+ use the new xstrnlen instead of strlen.
+
+ * conf/checkmount/checkmount_{default,svr4}.c
+ (fixmount_check_mount): document why NOT to use xstrnlen.
+
+ * libamu/xutil.c: am_hostname need not be MAXHOSTNAMELEN+1 any
+ more, just MAXHOSTNAMELEN.
+
+ * libamu/xutil.c (real_plog): use strlcpy (not xstrlcpy to avoid
+ recursion, since xstrlcpy may use plog).
+
* libamu/util.c (xstrlcpy): truncating a string is serious. Use
XLOG_ERROR not XLOG_WARNING.
* SUCH DAMAGE.
*
*
- * $Id: am_ops.c,v 1.22 2005/03/06 01:26:30 ib42 Exp $
+ * $Id: am_ops.c,v 1.23 2005/04/07 05:50:38 ezk Exp $
*
*/
tmpstr;
tmpstr = strtok(NULL, ",")) {
/* copy option to temp buffer */
- strncpy(oneopt, tmpstr, 80);
- oneopt[79] = '\0';
+ xstrlcpy(oneopt, tmpstr, 80);
/* if option has a value such as rsize=1024, chop the value part */
if ((eq = haseq(oneopt)))
*eq = '\0';
* SUCH DAMAGE.
*
*
- * $Id: amfs_host.c,v 1.29 2005/01/03 20:56:45 ezk Exp $
+ * $Id: amfs_host.c,v 1.30 2005/04/07 05:50:38 ezk Exp $
*
*/
* 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));
+ xstrlcpy(fs_name, mf->mf_info, MAXPATHLEN);
if ((rfs_dir = strchr(fs_name, ':')) == (char *) 0) {
plog(XLOG_FATAL, "amfs_host_mount: mf_info has no colon");
error = EINVAL;
* SUCH DAMAGE.
*
*
- * $Id: nfs_subr.c,v 1.26 2005/03/31 21:59:43 ezk Exp $
+ * $Id: nfs_subr.c,v 1.27 2005/04/07 05:50:38 ezk Exp $
*
*/
if (fp->fhh_type != 0) {
/* New filehandle type */
- int len = sizeof(*fhp);
- char *path = xmalloc(len + 1);
- strncpy(path, (char *) fhp, len);
- path[len+1] = '\0'; /* just to be safe */
+ char *path = xmalloc(sizeof(*fhp));
+ xstrlcpy(path, (char *) fhp, sizeof(*fhp));
/* dlog("fh_to_mp3: new filehandle: %s", path); */
ap = path_to_exported_ap(path);
pathlen = strlen(mp->am_path);
if (pathlen <= sizeof(*fhp)) {
/* dlog("mp_to_fh: new filehandle: %s", mp->am_path); */
- strncpy((char *) fhp, mp->am_path, pathlen);
+ xstrlcpy((char *) fhp, mp->am_path, pathlen);
} else {
struct am_fh *fp = (struct am_fh *) fhp;
* SUCH DAMAGE.
*
*
- * $Id: ops_nfs.c,v 1.40 2005/03/13 03:36:50 ezk Exp $
+ * $Id: ops_nfs.c,v 1.41 2005/04/07 05:50:38 ezk Exp $
*
*/
#ifdef MOUNT_TABLE_ON_FILE
*colon = '\0';
#endif /* MOUNT_TABLE_ON_FILE */
- strncpy(host, fs_name, sizeof(host));
+ xstrlcpy(host, fs_name, sizeof(host));
#ifdef MOUNT_TABLE_ON_FILE
*colon = ':';
#endif /* MOUNT_TABLE_ON_FILE */
* SUCH DAMAGE.
*
*
- * $Id: opts.c,v 1.36 2005/02/17 21:32:05 ezk Exp $
+ * $Id: opts.c,v 1.37 2005/04/07 05:50:38 ezk Exp $
*
*/
int len = dp - cp;
if (BUFSPACE(ep, len)) {
- strncpy(ep, cp, len);
+ xstrlcpy(ep, cp, len);
ep += len;
} else {
plog(XLOG_ERROR, EXPAND_ERROR, opt);
* Put the string into another buffer so
* we can do comparisons.
*/
- strncpy(nbuf, cp, len);
- nbuf[len] = '\0';
+ xstrlcpy(nbuf, cp, len);
/*
* Advance cp
* SUCH DAMAGE.
*
*
- * $Id: checkmount_default.c,v 1.9 2005/01/03 20:56:45 ezk Exp $
+ * $Id: checkmount_default.c,v 1.10 2005/04/07 05:50:38 ezk Exp $
*
*/
/* swap files never show up in mtab, only root fs */
if ((swap = strstr(path, "swap"))) {
- strncpy(swap, "root", 4);
+ strncpy(swap, "root", 4); /* this should NOT use xstrlcpy */
found = fixmount_check_mount(host, hostaddr, path);
- strncpy(swap, "swap", 4);
+ strncpy(swap, "swap", 4); /* this should NOT use xstrlcpy */
}
}
return found;
* SUCH DAMAGE.
*
*
- * $Id: checkmount_svr4.c,v 1.9 2005/01/03 20:56:45 ezk Exp $
+ * $Id: checkmount_svr4.c,v 1.10 2005/04/07 05:50:38 ezk Exp $
*
*/
/* swap files never show up in mtab, only root fs */
if ((swap = strstr(path, "swap"))) {
- strncpy(swap, "root", 4);
+ strncpy(swap, "root", 4); /* this should NOT use xstrlcpy */
found = fixmount_check_mount(host, hostaddr, path);
- strncpy(swap, "swap", 4);
+ strncpy(swap, "swap", 4); /* this should NOT use xstrlcpy */
}
}
return found;
/* $srcdir/conf/hn_dref/hn_dref_isc3.h */
-#define NFS_HN_DREF(dst, src) { \
- strncpy((dst), (src), MAXHOSTNAMELEN); \
- (dst)[MAXHOSTNAMELEN] = '\0'; \
- }
+#define NFS_HN_DREF(dst, src) xstrlcpy((dst), (src), MAXHOSTNAMELEN)
/* $srcdir/conf/hn_dref/hn_dref_linux.h */
-#define NFS_HN_DREF(dst, src) strncpy((dst), (src), MAXHOSTNAMELEN)
+#define NFS_HN_DREF(dst, src) xstrlcpy((dst), (src), MAXHOSTNAMELEN)
* SUCH DAMAGE.
*
*
- * $Id: mount_linux.c,v 1.41 2005/03/05 07:09:17 ezk Exp $
+ * $Id: mount_linux.c,v 1.42 2005/04/07 05:50:38 ezk Exp $
*/
/*
}
memset(&loopinfo, 0, sizeof(loopinfo));
- strncpy(loopinfo.lo_name, file, LO_NAME_SIZE-1);
- loopinfo.lo_name[LO_NAME_SIZE-1] = '\0';
+ xstrlcpy(loopinfo.lo_name, file, LO_NAME_SIZE);
loopinfo.lo_offset = 0;
if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
* SUCH DAMAGE.
*
*
- * $Id: mount_svr4.c,v 1.11 2005/01/03 20:56:45 ezk Exp $
+ * $Id: mount_svr4.c,v 1.12 2005/04/07 05:50:38 ezk Exp $
*
*/
* Save a copy of the mount options. The kernel will overwrite them with
* those it recognizes.
*/
- strncpy(mountopts, optstr, sizeof(mountopts));
- mountopts[MAX_MNTOPT_STR-1] = '\0';
+ xstrlcpy(mountopts, optstr, MAX_MNTOPT_STR);
#endif /* defined(MNT2_GEN_OPT_OPTIONSTR) && defined(MAX_MNTOPT_STR) */
#if defined(MOUNT_TYPE_NFS3) && defined(MNTTAB_TYPE_NFS3)
* SUCH DAMAGE.
*
*
- * $Id: mtab_isc3.c,v 1.10 2005/01/03 20:56:45 ezk Exp $
+ * $Id: mtab_isc3.c,v 1.11 2005/04/07 05:50:38 ezk Exp $
*
*/
mntent_t *new_mp = ALLOC(mntent_t);
char nullcpy[128];
- strncpy(nullcpy, mp->mt_dev, 32);
- nullcpy[32] = '\0';
+ xstrlcpy(nullcpy, mp->mt_dev, 32);
new_mp->mnt_fsname = strdup(nullcpy);
- strncpy(nullcpy, mp->mt_filsys, 32);
- nullcpy[32] = '\0';
+ xstrlcpy(nullcpy, mp->mt_filsys, 32);
new_mp->mnt_dir = strdup(nullcpy);
- strncpy(nullcpy, mp->mt_fstyp, 16);
- nullcpy[16] = '\0';
+ xstrlcpy(nullcpy, mp->mt_fstyp, 16);
new_mp->mnt_type = strdup(nullcpy);
- strncpy(nullcpy, mp->mt_mntopts, 64);
- nullcpy[64] = '\0';
+ xstrlcpy(nullcpy, mp->mt_mntopts, 64);
new_mp->mnt_opts = strdup(nullcpy);
new_mp->mnt_freq = 0;
{
static mntent_t mt;
- memset(mt.mt_dev, '\0', 32);
- strncpy(mt.mt_dev, mnt->mnt_fsname, 32);
- memset(mt.mt_filsys, '\0', 32);
- strncpy(mt.mt_filsys, mnt->mnt_dir, 32);
+ xstrlcpy(mt.mt_dev, mnt->mnt_fsname, 32);
+ xstrlcpy(mt.mt_filsys, mnt->mnt_dir, 32);
mt.mt_ro_flg = mnt->mnt_ro;
mt.mt_time = mnt->mnt_time;
- memset(mt.mt_fstyp, '\0', 16);
- strncpy(mt.mt_fstyp, mnt->mnt_type, 16);
- memset(mt.mt_mntopts, '\0', 64);
- strncpy(mt.mt_mntopts, mnt->mnt_opts, 64);
+ xstrlcpy(mt.mt_fstyp, mnt->mnt_type, 16);
+ xstrlcpy(mt.mt_mntopts, mnt->mnt_opts, 64);
return &mt;
}
* SUCH DAMAGE.
*
*
- * $Id: fixmount.c,v 1.11 2005/01/03 20:56:46 ezk Exp $
+ * $Id: fixmount.c,v 1.12 2005/04/07 05:50:38 ezk Exp $
*
*/
} else if (!(he = gethostbyname(name1))) {
return 0;
} else {
- strncpy(lasthost, name1, sizeof(lasthost) - 1);
+ xstrlcpy(lasthost, name1, MAXHOSTNAMELEN);
memcpy(&addr1, he->h_addr, sizeof(addr1));
return (addr1.s_addr == addr2.s_addr);
}
struct timeval tv;
char *pathp = dir_path;
- strncpy(dir_path, ml->ml_directory, sizeof(dir_path));
+ xstrlcpy(dir_path, ml->ml_directory, sizeof(dir_path));
if (!fixit) {
printf("%s: bogus mount %s:%s\n", host, ml->ml_hostname, ml->ml_directory);
break;
case 'h':
- strncpy(thishost, optarg, sizeof(thishost));
- thishost[sizeof(thishost) - 1] = '\0';
+ xstrlcpy(thishost, optarg, sizeof(thishost));
break;
case '?':
inet_ntoa(thisaddr));
exit(1);
}
- strncpy(thishost, he->h_name, sizeof(thishost));
- thishost[sizeof(thishost) - 1] = '\0';
+ xstrlcpy(thishost, he->h_name, sizeof(thishost));
} else {
thisaddr.s_addr = INADDR_NONE;
}
* SUCH DAMAGE.
*
*
- * $Id: fsinfo.c,v 1.14 2005/01/03 20:56:46 ezk Exp $
+ * $Id: fsinfo.c,v 1.15 2005/04/07 05:50:38 ezk Exp $
*
*/
break;
case 'h':
- strncpy(hostname, optarg, sizeof(hostname) - 1);
+ xstrlcpy(hostname, optarg, sizeof(hostname));
break;
case 'e':
* SUCH DAMAGE.
*
*
- * $Id: stubs.c,v 1.16 2005/01/03 20:56:46 ezk Exp $
+ * $Id: stubs.c,v 1.17 2005/04/07 05:50:39 ezk Exp $
*
* HLFSD was written at Columbia University Computer Science Department, by
* Erez Zadok <ezk@cs.columbia.edu> and Alexander Dupuy <dupuy@cs.columbia.edu>
res.dr_u.dr_drok_u.drok_attributes = un_fattr;
memset((char *) &un_fhandle, 0, sizeof(am_nfs_fh));
*(u_int *) un_fhandle.fh_data = (u_int) untab[idx].uid;
- strncpy((char *) &un_fhandle.fh_data[sizeof(int)],
- untab[idx].username,
- sizeof(am_nfs_fh) - sizeof(int));
+ xstrlcpy((char *) &un_fhandle.fh_data[sizeof(int)],
+ untab[idx].username,
+ sizeof(am_nfs_fh) - sizeof(int));
res.dr_u.dr_drok_u.drok_fhandle = un_fhandle;
res.dr_status = NFS_OK;
dlog("nfs_lookup: successful lookup for uid=%ld, gid=%ld: username=%s",
* SUCH DAMAGE.
*
*
- * $Id: xutil.c,v 1.36 2005/04/07 03:50:42 ezk Exp $
+ * $Id: xutil.c,v 1.37 2005/04/07 05:50:39 ezk Exp $
*
*/
FILE *logfp = NULL;
static char *am_progname = "unknown"; /* "amd" */
-static char am_hostname[MAXHOSTNAMELEN + 1] = "unknown"; /* Hostname */
+static char am_hostname[MAXHOSTNAMELEN] = "unknown"; /* Hostname */
pid_t am_mypid = -1; /* process ID */
serv_state amd_state; /* amd's state */
int foreground = 1; /* 1 == this is the top-level server */
void
am_set_hostname(char *hn)
{
- strncpy(am_hostname, hn, MAXHOSTNAMELEN);
- am_hostname[MAXHOSTNAMELEN] = '\0';
+ xstrlcpy(am_hostname, hn, MAXHOSTNAMELEN);
}
switch (last_count) {
case 0: /* never printed at all */
last_count = 1;
- strncpy(last_msg, msg, 1024);
+ if (strlcpy(last_msg, msg, 1024) >= 1024) /* don't use xstrlcpy here (recursive!) */
+ fprintf(stderr, "real_plog: string \"%s\" truncated to \"%s\"\n", last_msg, msg);
last_lvl = lvl;
show_time_host_and_name(lvl); /* mimic syslog header */
fwrite(msg, ptr - msg, 1, logfp);
last_count++;
} else { /* last msg printed once, new one differs */
/* last_count remains at 1 */
- strncpy(last_msg, msg, 1024);
+ if (strlcpy(last_msg, msg, 1024) >= 1024) /* don't use xstrlcpy here (recursive!) */
+ fprintf(stderr, "real_plog: string \"%s\" truncated to \"%s\"\n", last_msg, msg);
last_lvl = lvl;
show_time_host_and_name(lvl); /* mimic syslog header */
fwrite(msg, ptr - msg, 1, logfp);
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);
+ if (strlcpy(last_msg, msg, 1024) >= 1024) /* don't use xstrlcpy here (recursive!) */
+ fprintf(stderr, "real_plog: string \"%s\" truncated to \"%s\"\n", last_msg, msg);
last_count = 1;
last_lvl = lvl;
show_time_host_and_name(lvl); /* mimic syslog header */