* libamu/xutil.c (am_set_hostname),
authorErez Zadok <ezk@cs.sunysb.edu>
Thu, 7 Apr 2005 05:50:38 +0000 (05:50 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Thu, 7 Apr 2005 05:50:38 +0000 (05:50 +0000)
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).

17 files changed:
ChangeLog
amd/am_ops.c
amd/amfs_host.c
amd/nfs_subr.c
amd/ops_nfs.c
amd/opts.c
conf/checkmount/checkmount_default.c
conf/checkmount/checkmount_svr4.c
conf/hn_dref/hn_dref_isc3.h
conf/hn_dref/hn_dref_linux.h
conf/mount/mount_linux.c
conf/mount/mount_svr4.c
conf/mtab/mtab_isc3.c
fixmount/fixmount.c
fsinfo/fsinfo.c
hlfsd/stubs.c
libamu/xutil.c

index e083a26465162dda7ac13035eafe8b37b1ccea2b..4c01ffb69d35cc4cc06e795a8898baeb3310673b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,30 @@
 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.
 
index 64a024d5e9b98c07132a25ef0d09c49fc5f3b82c..1d596f9d92e967d81022f854533bfe0d9c740970 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -327,8 +327,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';
+    xstrlcpy(oneopt, tmpstr, 80);
     /* if option has a value such as rsize=1024, chop the value part */
     if ((eq = haseq(oneopt)))
       *eq = '\0';
index 988d4c35b8ce8fb78ad62c42803a29e8c2afa767..910c70518266b7c15a2bfe398e7debec71cb56c1 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -465,7 +465,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));
+  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;
index a4ec4f44c4164250ec604b7aeac6ec6e301077ac..fd3b347954d2714b7ac766800fe126303a286641 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -614,10 +614,8 @@ fh_to_mp3(am_nfs_fh *fhp, int *rp, int vop)
 
   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);
@@ -764,7 +762,7 @@ mp_to_fh(am_node *mp, am_nfs_fh *fhp)
   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;
 
index 9303ae1bd0f12f6bc9426bbf3c69a6d53f678204..055dbec86b407ff059c8bd7f74abf489a2928881 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -776,7 +776,7 @@ mount_nfs_fh(am_nfs_handle_t *fhp, char *mntdir, char *fs_name, mntfs *mf)
 #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 */
index 9d8c8b80b429f694cdaffe2c4230881a35970e17..81b065ea40feb7671169a8c26b1bb16d38aa8ab7 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -1028,7 +1028,7 @@ expand_op(char *opt, int sel_p)
       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);
@@ -1116,8 +1116,7 @@ expand_op(char *opt, int sel_p)
        * Put the string into another buffer so
        * we can do comparisons.
        */
-      strncpy(nbuf, cp, len);
-      nbuf[len] = '\0';
+      xstrlcpy(nbuf, cp, len);
 
       /*
        * Advance cp
index 9b4513511f89a2794f7413a973ecccab0d892688..30fe5ff3fb79b08d273ac5f6a2e72b54fbb3336f 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -100,9 +100,9 @@ fixmount_check_mount(char *host, struct in_addr hostaddr, char *path)
 
     /* 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;
index 31124bc3149974c7afad3deec556b4255dc1f12d..4ef5b6414ba7126fe15da6179d446c9872d395de 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -91,9 +91,9 @@ fixmount_check_mount(char *host, struct in_addr hostaddr, char *path)
 
     /* 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;
index ec484c68cb63879a33ab3fc6922eb317b657af2c..82291c19fcf8918736ef5479edf136be602950af 100644 (file)
@@ -1,5 +1,2 @@
 /* $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)
index bc6dc456dde710467b3de1ed78e65c61d8530de4..cf01d300a8a683813f8747ed09b9206774cce219 100644 (file)
@@ -1,2 +1,2 @@
 /* $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)
index 1765e80b54499f4582efe2961c20b31da974bd1d..c4bc14df43c1b61fa59e61cbce99e9bd29032632 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  */
 
 /*
@@ -826,8 +826,7 @@ setup_loop_device(const char *file)
   }
 
   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) {
index 4e6437316df2c7e808aa10993c552a724dc7ca1c..a0b2aecbe6d2b109bf605ca9435606ba6fbd0b3f 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -82,8 +82,7 @@ mount_svr4(char *fsname, char *dir, int flags, MTYPE_TYPE type, caddr_t data, co
    * 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)
index ea6ca8ecc2937a955dd6cda0362a6931a42200cf..71526971099c6ba148713f93c05638c1d66e8f7d 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -114,20 +114,16 @@ mnt_dup(mntent_t *mp)
   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;
@@ -146,18 +142,14 @@ mtab_of(mntent_t *mnt)
 {
   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;
 }
index b96051ce5b212a3c3ed5c2cedd21a21fecf0ed4c..4dbcdd1f82adafff5afca20ab0321646d6e8545d 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -119,7 +119,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);
+      xstrlcpy(lasthost, name1, MAXHOSTNAMELEN);
       memcpy(&addr1, he->h_addr, sizeof(addr1));
       return (addr1.s_addr == addr2.s_addr);
     }
@@ -163,7 +163,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));
+  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);
@@ -325,8 +325,7 @@ main(int argc, char *argv[])
       break;
 
     case 'h':
-      strncpy(thishost, optarg, sizeof(thishost));
-      thishost[sizeof(thishost) - 1] = '\0';
+      xstrlcpy(thishost, optarg, sizeof(thishost));
       break;
 
     case '?':
@@ -366,8 +365,7 @@ main(int argc, char *argv[])
              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;
   }
index be4539ce446c23adc7d51e53a1059436357ee7c4..bc14181491406c948da115e444b000397e74bed0 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -124,7 +124,7 @@ fsi_get_args(int c, char *v[])
       break;
 
     case 'h':
-      strncpy(hostname, optarg, sizeof(hostname) - 1);
+      xstrlcpy(hostname, optarg, sizeof(hostname));
       break;
 
     case 'e':
index 37030ce79a01d092869a953a75426ccd4481cebb..e7d50b8ae84bb788645200343a7db59c7fe32d39 100644 (file)
@@ -37,7 +37,7 @@
  * 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>
@@ -284,9 +284,9 @@ nfsproc_lookup_2_svc(nfsdiropargs *argp, struct svc_req *rqstp)
       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",
index 71de2382436a78124b44276ac729364b39bcf277..c5ef2c6b6cc05fc1c6f8c2571c5108d3b0e85b38 100644 (file)
@@ -37,7 +37,7 @@
  * 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 $
  *
  */
 
@@ -55,7 +55,7 @@
 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 */
@@ -149,8 +149,7 @@ am_get_progname(void)
 void
 am_set_hostname(char *hn)
 {
-  strncpy(am_hostname, hn, MAXHOSTNAMELEN);
-  am_hostname[MAXHOSTNAMELEN] = '\0';
+  xstrlcpy(am_hostname, hn, MAXHOSTNAMELEN);
 }
 
 
@@ -506,7 +505,8 @@ 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);
+    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);
@@ -518,7 +518,8 @@ 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);
+      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);
@@ -545,7 +546,8 @@ 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);
+      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 */