]> diplodocus.org Git - nmh/commitdiff
Subtracted 1 from size argument in some calls to strncpy(3).
authorDavid Levine <levinedl@acm.org>
Sun, 15 Mar 2020 21:14:36 +0000 (17:14 -0400)
committerDavid Levine <levinedl@acm.org>
Sun, 15 Mar 2020 21:14:36 +0000 (17:14 -0400)
This fixed "specified bound [n] equals destination size" warnings
found by gcc -Wstringop-truncation.

Also, fixed harmless copy-and-paste error (sizeof(tmpfil) instead
of sizeof(drft) in uip/rcvdist.c) introduced in commit 2f689a1cb.

33 files changed:
sbr/addrsbr.c
sbr/folder_delmsgs.c
sbr/folder_pack.c
sbr/m_draft.c
sbr/m_maildir.c
sbr/makedir.c
sbr/mts.c
test/getfullname.c
uip/annosbr.c
uip/burst.c
uip/comp.c
uip/dist.c
uip/distsbr.c
uip/flist.c
uip/folder.c
uip/forw.c
uip/forwsbr.c
uip/mhbuild.c
uip/mhbuildsbr.c
uip/mhlsbr.c
uip/mhshowsbr.c
uip/mhstoresbr.c
uip/popsbr.c
uip/post.c
uip/rcvdist.c
uip/refile.c
uip/repl.c
uip/rmf.c
uip/sendsbr.c
uip/slocal.c
uip/sortm.c
uip/viamail.c
uip/whatnowsbr.c

index af8ecd4d00f4c40acb55bc721b5cde072f62db7b..2eb20b0b8190e22655ffe59276642718596074ec 100644 (file)
@@ -100,7 +100,7 @@ getname (const char *addrs)
        return NULL;
     }
 
        return NULL;
     }
 
-    strncpy (adr, ap->text, sizeof(adr));
+    strncpy (adr, ap->text, sizeof(adr) - 1);
     pers = ap->pers;
     mbox = ap->mbox;
     host = ap->host;
     pers = ap->pers;
     mbox = ap->mbox;
     host = ap->host;
@@ -109,7 +109,7 @@ getname (const char *addrs)
     ingrp = ap->ingrp;
     note = ap->note;
     if (ap->err && *ap->err)
     ingrp = ap->ingrp;
     note = ap->note;
     if (ap->err && *ap->err)
-       strncpy (err, ap->err, sizeof(err));
+       strncpy (err, ap->err, sizeof(err) - 1);
 
     return adr;
 }
 
     return adr;
 }
index 533ab9bae2847104044ebb6de3c0880a5a2de4a9..a385827ba498f37c2d0ccdac9f63258af87d8254 100644 (file)
@@ -124,7 +124,7 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook)
                }
            } else {
                /* or rename messages with standard prefix */
                }
            } else {
                /* or rename messages with standard prefix */
-               strncpy (buf, m_backup (dp), sizeof(buf));
+               strncpy (buf, m_backup (dp), sizeof(buf) - 1);
                if (rename (dp, buf) == -1) {
                    admonish (buf, "unable to rename %s to", dp);
                    retval = -1;
                if (rename (dp, buf) == -1) {
                    admonish (buf, "unable to rename %s to", dp);
                    retval = -1;
index ba84d1f7f01435dd246612a19a05ff85c6b19bb5..7fdfcf8536d9aa34bf9b49f73005831ac7f2ac5b 100644 (file)
@@ -49,8 +49,8 @@ folder_pack (struct msgs **mpp, int verbose)
     for (msgnum = mp->lowmsg, hole = 1; msgnum <= mp->hghmsg; msgnum++) {
        if (does_exist (mp, msgnum)) {
            if (msgnum != hole) {
     for (msgnum = mp->lowmsg, hole = 1; msgnum <= mp->hghmsg; msgnum++) {
        if (does_exist (mp, msgnum)) {
            if (msgnum != hole) {
-               strncpy (newmsg, m_name (hole), sizeof(newmsg));
-               strncpy (oldmsg, m_name (msgnum), sizeof(oldmsg));
+               strncpy (newmsg, m_name (hole), sizeof(newmsg) - 1);
+               strncpy (oldmsg, m_name (msgnum), sizeof(oldmsg) - 1);
                if (verbose)
                    printf ("message %s becomes %s\n", oldmsg, newmsg);
 
                if (verbose)
                    printf ("message %s becomes %s\n", oldmsg, newmsg);
 
index 342f44f02df54d60ae922471e309b871b38b1391..803ed75051ca849099b783d3b3a03bc6cf68376e 100644 (file)
@@ -45,7 +45,7 @@ m_draft (char *folder, char *msg, int use, int *isdf)
     if (chdir (m_maildir ("")) < 0) {
        advise (m_maildir (""), "chdir");
     }
     if (chdir (m_maildir ("")) < 0) {
        advise (m_maildir (""), "chdir");
     }
-    strncpy (buffer, m_maildir (folder), sizeof(buffer));
+    strncpy (buffer, m_maildir (folder), sizeof(buffer) - 1);
 
     create_folder (buffer, 0, done);
 
 
     create_folder (buffer, 0, done);
 
index 5edc936047b8f325e418d3cfa973003f1f8d285c..888b8d223fd47ec7b1a9554038c87c16f4169a8b 100644 (file)
@@ -78,7 +78,7 @@ exmaildir (char *folder)
            && strcmp (folder, DOT)
            && strcmp (folder, DOTDOT)
            && !has_prefix(folder, PWD))) {
            && strcmp (folder, DOT)
            && strcmp (folder, DOTDOT)
            && !has_prefix(folder, PWD))) {
-       strncpy (mailfold, folder, sizeof(mailfold));
+       strncpy (mailfold, folder, sizeof(mailfold) - 1);
        return mailfold;
     }
 
        return mailfold;
     }
 
index 123055373987c99cc75bf2ae825863faa8b10f1d..3bbfb6867b624936c7cad6f9f0832ceed59a7a13 100644 (file)
@@ -44,7 +44,7 @@ makedir (const char *dir)
        to interact with the umask.  Clear it temporarily. */
     saved_umask = umask(0);
 
        to interact with the umask.  Clear it temporarily. */
     saved_umask = umask(0);
 
-    c = strncpy(path, dir, sizeof(path));
+    c = strncpy(path, dir, sizeof(path) - 1);
 
     bool had_an_error = false;
     while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) {
 
     bool had_an_error = false;
     while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) {
index 4c95f481c60959c56bf086e0d18cf3f5b1ec0c4f..5f4e3676daa16d85198502af87872aff8e029919 100644 (file)
--- a/sbr/mts.c
+++ b/sbr/mts.c
@@ -246,7 +246,7 @@ LocalName (int flag)
 
     /* check if the mts.conf file specifies a "localname" */
     if (*localname && flag == 0) {
 
     /* check if the mts.conf file specifies a "localname" */
     if (*localname && flag == 0) {
-       strncpy (buf, localname, sizeof(buffer0));
+       strncpy (buf, localname, sizeof(buffer0) - 1);
     } else {
        memset(buf, 0, sizeof(buffer0));
        /* first get our local name */
     } else {
        memset(buf, 0, sizeof(buffer0));
        /* first get our local name */
@@ -293,7 +293,7 @@ SystemName (void)
 
     /* check if mts.conf file specifies a "systemname" */
     if (*systemname) {
 
     /* check if mts.conf file specifies a "systemname" */
     if (*systemname) {
-       strncpy (buffer, systemname, sizeof(buffer));
+       strncpy (buffer, systemname, sizeof(buffer) - 1);
        return buffer;
     }
 
        return buffer;
     }
 
@@ -409,7 +409,7 @@ getuserinfo (void)
        char *at_sign = strchr (np, '@');
        char *right_angle_bracket = strchr (np, '>');
 
        char *at_sign = strchr (np, '@');
        char *right_angle_bracket = strchr (np, '>');
 
-       strncpy(localmbox, np, sizeof(localmbox));
+       strncpy(localmbox, np, sizeof(localmbox) - 1);
 
        if (left_angle_bracket  &&  at_sign  &&  right_angle_bracket) {
            if (at_sign > left_angle_bracket  &&
 
        if (left_angle_bracket  &&  at_sign  &&  right_angle_bracket) {
            if (at_sign > left_angle_bracket  &&
index 14f454238a78f412636f143635bdec3595b87346..91777c3963da9857763afe418cad80d3f9204e8e 100644 (file)
@@ -36,7 +36,7 @@ main(int argc, char *argv[])
                strncpy(buf, pwd->pw_gecos, sizeof(buf));
                buf[sizeof(buf) - 1] = '\0';
        } else
                strncpy(buf, pwd->pw_gecos, sizeof(buf));
                buf[sizeof(buf) - 1] = '\0';
        } else
-               strncpy(buf, argv[1], sizeof(buf));
+               strncpy(buf, argv[1], sizeof(buf) - 1);
 
        /*
         * Perform the same processing that getuserinfo() does.
 
        /*
         * Perform the same processing that getuserinfo() does.
index 8b0c8843e23e4db585e9ad3ca8d13801ac4d581d..dbd769a527dfc375e95f3224fd1a5ec79cbd862a 100644 (file)
@@ -194,7 +194,7 @@ annosbr (int fd, char *file, char *comp, char *text, bool inplace, bool datesw,
     if ((cp = m_mktemp2(file, "annotate", NULL, &tmp)) == NULL) {
        die("unable to create temporary file");
     }
     if ((cp = m_mktemp2(file, "annotate", NULL, &tmp)) == NULL) {
        die("unable to create temporary file");
     }
-    strncpy (tmpfil, cp, sizeof(tmpfil));
+    strncpy (tmpfil, cp, sizeof(tmpfil) - 1);
     chmod (tmpfil, mode);
 
     /*
     chmod (tmpfil, mode);
 
     /*
@@ -422,7 +422,7 @@ annosbr (int fd, char *file, char *comp, char *text, bool inplace, bool datesw,
        close (tmpfd);
        (void) m_unlink (tmpfil);
     } else {
        close (tmpfd);
        (void) m_unlink (tmpfil);
     } else {
-       strncpy (buffer, m_backup (file), sizeof(buffer));
+       strncpy (buffer, m_backup (file), sizeof(buffer) - 1);
        if (rename (file, buffer) == NOTOK) {
            switch (errno) {
                case ENOENT:    /* unlinked early - no annotations */
        if (rename (file, buffer) == NOTOK) {
            switch (errno) {
                case ENOENT:    /* unlinked early - no annotations */
index 289ce81945444dbd495e55d2b0002af76962e3b4..b80d9ce977217d8ffecebee6b21dec6a69748812 100644 (file)
@@ -434,8 +434,8 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
      */
     if (inplace) {
        for (i = mp->hghmsg; j > msgnum; i--, j--) {
      */
     if (inplace) {
        for (i = mp->hghmsg; j > msgnum; i--, j--) {
-           strncpy (f1, m_name (i), sizeof(f1));
-           strncpy (f2, m_name (j), sizeof(f2));
+           strncpy (f1, m_name (i), sizeof(f1) - 1);
+           strncpy (f2, m_name (j), sizeof(f2) - 1);
            if (does_exist (mp, j)) {
                if (verbosw)
                    printf ("message %d becomes message %d\n", j, i);
            if (does_exist (mp, j)) {
                if (verbosw)
                    printf ("message %d becomes message %d\n", j, i);
@@ -483,8 +483,8 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
            die("unable to create temporary file in %s",
                  get_temp_dir());
        }
            die("unable to create temporary file in %s",
                  get_temp_dir());
        }
-       strncpy (f2, tempfile, sizeof(f2));
-       strncpy (f1, m_name (i), sizeof(f1));
+       strncpy (f2, tempfile, sizeof(f2) - 1);
+       strncpy (f1, m_name (i), sizeof(f1) - 1);
 
        if (verbosw && i != msgnum)
            printf ("message %d of digest %d becomes message %d\n", j, msgnum, i);
 
        if (verbosw && i != msgnum)
            printf ("message %d of digest %d becomes message %d\n", j, msgnum, i);
@@ -496,7 +496,7 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
        fclose (out);
 
        if (i == msgnum) {
        fclose (out);
 
        if (i == msgnum) {
-           strncpy (f3, m_backup (f1), sizeof(f3));
+           strncpy (f3, m_backup (f1), sizeof(f3) - 1);
            if (rename (f1, f3) == NOTOK)
                admonish (f3, "unable to rename %s to", f1);
 
            if (rename (f1, f3) == NOTOK)
                admonish (f3, "unable to rename %s to", f1);
 
index 69210f81ed0437515fad73dc2a12ff0d17f7f864..c16e89d0bd2d56fce4845c4131ac3f123b692c63 100644 (file)
@@ -340,7 +340,7 @@ main (int argc, char **argv)
 
 try_it_again:
     strncpy (drft, build ? m_maildir ("draft")
 
 try_it_again:
     strncpy (drft, build ? m_maildir ("draft")
-                       : m_draft (dfolder, file, use, &isdf), sizeof(drft));
+                       : m_draft (dfolder, file, use, &isdf), sizeof(drft) - 1);
 
     /*
      * Check if we have an existing draft
 
     /*
      * Check if we have an existing draft
index e6720ae71886db99f90692f604faf51309c1210c..1c2b596acabdaabbc47327a2bde7420d7a3434f3 100644 (file)
@@ -253,7 +253,7 @@ main (int argc, char **argv)
        die("can't mix files and folders/msgs");
 
 try_it_again:
        die("can't mix files and folders/msgs");
 
 try_it_again:
-    strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft));
+    strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft) - 1);
 
     /* Check if draft already exists */
     if (stat (drft, &st) != NOTOK) {
 
     /* Check if draft already exists */
     if (stat (drft, &st) != NOTOK) {
index 4df836ef5f0f16952e91b3b228c21fa07688eb78..f830bc9b3054dbb96f1d1e8c8f7a79082eafa313 100644 (file)
@@ -156,7 +156,7 @@ ready_msg (char *msgnam)
     if (cp == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
     if (cp == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
-    strncpy(tmpfil, cp, sizeof(tmpfil));
+    strncpy(tmpfil, cp, sizeof(tmpfil) - 1);
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
        die("no file descriptors -- you lose big");
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
        die("no file descriptors -- you lose big");
@@ -187,7 +187,7 @@ ready_msg (char *msgnam)
                          get_temp_dir());
                 }
                 fchmod(txtfd, 0600);
                          get_temp_dir());
                 }
                 fchmod(txtfd, 0600);
-               strncpy (tmpfil, cp, sizeof(tmpfil));
+               strncpy (tmpfil, cp, sizeof(tmpfil) - 1);
                if ((out = dup (txtfd)) == NOTOK
                        || (ofp = fdopen (out, "w")) == NULL)
                    die("no file descriptors -- you lose big");
                if ((out = dup (txtfd)) == NOTOK
                        || (ofp = fdopen (out, "w")) == NULL)
                    die("no file descriptors -- you lose big");
index aedfd8842cca3b8d092fc7cfd55895a11398dd38..17dd672129dfd5d71c75e9b7124d1bce041be855 100644 (file)
@@ -234,7 +234,7 @@ main(int argc, char **argv)
         free (path ("./", TFOLDER));
 
     /* get current folder */
         free (path ("./", TFOLDER));
 
     /* get current folder */
-    strncpy (curfolder, getfolder(1), sizeof(curfolder));
+    strncpy (curfolder, getfolder(1), sizeof(curfolder) - 1);
 
     /* get nmh base directory */
     nmhdir = m_maildir ("");
 
     /* get nmh base directory */
     nmhdir = m_maildir ("");
@@ -316,7 +316,7 @@ ScanFolders(void)
 
     if (numfolders > 0) {
        /* Update context */
 
     if (numfolders > 0) {
        /* Update context */
-       strncpy (curfolder, foldersToDo[numfolders - 1], sizeof(curfolder));
+       strncpy (curfolder, foldersToDo[numfolders - 1], sizeof(curfolder) - 1);
        context_replace (pfolder, curfolder);/* update current folder */
        context_save ();                     /* save the context file */
 
        context_replace (pfolder, curfolder);/* update current folder */
        context_save ();                     /* save the context file */
 
index 8ab6528b7bb2d49400f68a3ad6e786c1f1bfdf57..6706ef878ce092ae6c2f8f51cc90cdc04c54a1a9 100644 (file)
@@ -363,10 +363,10 @@ main (int argc, char **argv)
                inform("no folder given for message %s, continuing...", msg);
            readonly_folders (); /* do any readonly folders */
            cp = context_find(pfolder);
                inform("no folder given for message %s, continuing...", msg);
            readonly_folders (); /* do any readonly folders */
            cp = context_find(pfolder);
-           strncpy (folder, FENDNULL(cp), sizeof(folder));
+           strncpy (folder, FENDNULL(cp), sizeof(folder) - 1);
            crawl_folders (".", get_folder_info_callback, NULL);
        } else {
            crawl_folders (".", get_folder_info_callback, NULL);
        } else {
-           strncpy (folder, argfolder, sizeof(folder));
+           strncpy (folder, argfolder, sizeof(folder) - 1);
            if (get_folder_info (argfolder, msg)) {
                context_replace (pfolder, argfolder);/* update current folder */
                context_save ();                     /* save the context file */
            if (get_folder_info (argfolder, msg)) {
                context_replace (pfolder, argfolder);/* update current folder */
                context_save ();                     /* save the context file */
@@ -379,7 +379,8 @@ main (int argc, char **argv)
                crawl_folders (folder, get_folder_info_callback, NULL);
        }
     } else {
                crawl_folders (folder, get_folder_info_callback, NULL);
        }
     } else {
-       strncpy (folder, argfolder ? argfolder : getfolder (1), sizeof(folder));
+       strncpy (folder, argfolder ? argfolder : getfolder (1),
+                sizeof(folder) - 1);
 
        /*
         * Check if folder exists.  If not, then see if
 
        /*
         * Check if folder exists.  If not, then see if
index 5194a5aab5cf13a4625db6cf25d4ea1c0f830ba2..530e61cdc4528346a599f539b648cc16ac9347cb 100644 (file)
@@ -339,7 +339,7 @@ main (int argc, char **argv)
 try_it_again:
 
     strncpy (drft, buildsw ? m_maildir ("draft")
 try_it_again:
 
     strncpy (drft, buildsw ? m_maildir ("draft")
-                         : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft));
+                 : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft) - 1);
 
     /* Check if a draft already exists */
     if (!buildsw && stat (drft, &st) != NOTOK) {
 
     /* Check if a draft already exists */
     if (!buildsw && stat (drft, &st) != NOTOK) {
index 1b6a92cb90843d91459acf874496c91884cad5a9..2e098bd5d13d8cf1be27ca8dfeb6fba78b946f96 100644 (file)
@@ -184,7 +184,7 @@ finished:
     if (cp == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
     if (cp == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
-    strncpy (tmpfil, cp, sizeof(tmpfil));
+    strncpy (tmpfil, cp, sizeof(tmpfil) - 1);
     (void) m_unlink (tmpfil);
     if ((in = dup (fileno (tmp))) == NOTOK)
        adios ("dup", "unable to");
     (void) m_unlink (tmpfil);
     if ((in = dup (fileno (tmp))) == NOTOK)
        adios ("dup", "unable to");
index 48f7e4b48ed3e99ddde31bc57e0621095a8fe121..66860eee8cb58ac9bd41ab19288e157c2697e767 100644 (file)
@@ -302,7 +302,7 @@ main (int argc, char **argv)
            die("unable to create temporary file in %s",
                  get_temp_dir());
        }
            die("unable to create temporary file in %s",
                  get_temp_dir());
        }
-       strncpy (infile, cp, sizeof(infile));
+       strncpy (infile, cp, sizeof(infile) - 1);
 
        /* copy standard input to temporary file */
        while ((n = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
 
        /* copy standard input to temporary file */
        while ((n = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
@@ -362,7 +362,7 @@ main (int argc, char **argv)
     if ((cp = m_mktemp2(compfile, invo_name, NULL, &fp_out)) == NULL) {
        die("unable to create temporary file");
     }
     if ((cp = m_mktemp2(compfile, invo_name, NULL, &fp_out)) == NULL) {
        die("unable to create temporary file");
     }
-    strncpy(outfile, cp, sizeof(outfile));
+    strncpy(outfile, cp, sizeof(outfile) - 1);
 
     /* output the message */
     output_message_fp (ct, fp_out, outfile);
 
     /* output the message */
     output_message_fp (ct, fp_out, outfile);
index b96e63ac03e86e812d7d9aa9bae7fc031eb4dede..6795025f2c64a749f0bfe280bd86d254e1f5f76f 100644 (file)
@@ -726,7 +726,7 @@ user_content (FILE *in, char *buf, CT *ctp, const char *infilename)
        ce->ce_unlink = 1;
 
        if (do_direct() && (buf[0] == '#' && buf[1] == '<')) {
        ce->ce_unlink = 1;
 
        if (do_direct() && (buf[0] == '#' && buf[1] == '<')) {
-           strncpy (content, buf + 2, sizeof(content));
+           strncpy (content, buf + 2, sizeof(content) - 1);
            inlineD = true;
            goto rock_and_roll;
        }
            inlineD = true;
            goto rock_and_roll;
        }
@@ -735,7 +735,8 @@ user_content (FILE *in, char *buf, CT *ctp, const char *infilename)
        /* the directive is implicit */
        strncpy (content, "text/plain", sizeof(content));
        headers = 0;
        /* the directive is implicit */
        strncpy (content, "text/plain", sizeof(content));
        headers = 0;
-       strncpy (buffer, (!do_direct() || buf[0] != '#') ? buf : buf + 1, sizeof(buffer));
+       strncpy (buffer, (!do_direct() || buf[0] != '#') ? buf : buf + 1,
+                sizeof(buffer) - 1);
        for (;;) {
            int i;
 
        for (;;) {
            int i;
 
index ffb39b9cbc19cde5855941881af5841c7ee58570..ade7e1c29953093164874b2b4b945645d3185f72 100644 (file)
@@ -610,7 +610,7 @@ mhl_format (char *file, int length, int width)
        }
 
        parptr = bp;
        }
 
        parptr = bp;
-       strncpy (name, parse(), sizeof(name));
+       strncpy (name, parse(), sizeof(name) - 1);
        switch (*parptr) {
            case '\0': 
            case ',': 
        switch (*parptr) {
            case '\0': 
            case ',': 
@@ -725,7 +725,7 @@ evalvar (struct mcomp *c1)
 
     if (!*parptr)
        return 0;
 
     if (!*parptr)
        return 0;
-    strncpy (name, parse(), sizeof(name));
+    strncpy (name, parse(), sizeof(name) - 1);
 
     if (!strcasecmp (name, "component")) {
        if (ptos (name, &c1->c_text))
 
     if (!strcasecmp (name, "component")) {
        if (ptos (name, &c1->c_text))
index cd53d14537bead05bd497a06f692a5f4717d55eb..a39459efbf941ad5ca61bf4be42091ba01bff64a 100644 (file)
@@ -379,7 +379,7 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked, struct format *
     }
 
     if (cracked) {
     }
 
     if (cracked) {
-       strncpy (buffer, cp, sizeof(buffer));
+       strncpy (buffer, cp, sizeof(buffer) - 1);
        goto got_command;
     }
 
        goto got_command;
     }
 
@@ -1041,7 +1041,7 @@ raw:
     if (ct->c_termproc) {
        char term[BUFSIZ];
 
     if (ct->c_termproc) {
        char term[BUFSIZ];
 
-       strncpy (term, buffer, sizeof(term));
+       strncpy (term, buffer, sizeof(term) - 1);
        snprintf (buffer, buflen, ct->c_termproc, term);
     }
 
        snprintf (buffer, buflen, ct->c_termproc, term);
     }
 
index 131650be59d9128d463fe730f878d310c17bd787..64b69bc00bec3fde6c84c7a83db5f27bafb678a4 100644 (file)
@@ -704,7 +704,7 @@ parse_format_string (CT ct, char *cp, char *buffer, int buflen, char *dir)
      * return (send content to standard output).
      */
     if (cp[0] == '-' && cp[1] == '\0') {
      * return (send content to standard output).
      */
     if (cp[0] == '-' && cp[1] == '\0') {
-       strncpy (buffer, cp, buflen);
+       strncpy (buffer, cp, buflen - 1);
        return 0;
     }
 
        return 0;
     }
 
index 3df93bd969ed0c018ded013429175745d9fc05a4..c1d520e9a9678c060ced1f956ee5cc1952a66faa 100644 (file)
@@ -67,7 +67,7 @@ check_mech(char *server_mechs, size_t server_mechs_size)
         if (strncasecmp(response, "SASL ", 5) == 0) {
             /* We've seen the SASL capability.  Grab the mech list. */
             sasl_capability = true;
         if (strncasecmp(response, "SASL ", 5) == 0) {
             /* We've seen the SASL capability.  Grab the mech list. */
             sasl_capability = true;
-            strncpy(server_mechs, response + 5, server_mechs_size);
+            strncpy(server_mechs, response + 5, server_mechs_size - 1);
         }
     }
 
         }
     }
 
index 246f5670c42227846f129353edc91d98564ab797..5243d55a1aa7da08aa3d36a34a111fc8efd73c76 100644 (file)
@@ -631,7 +631,7 @@ main (int argc, char **argv)
                die("unable to create temporary file in %s",
                      get_temp_dir());
            }
                die("unable to create temporary file in %s",
                      get_temp_dir());
            }
-            strncpy(tmpfil, cp, sizeof(tmpfil));
+            strncpy(tmpfil, cp, sizeof(tmpfil) - 1);
        }
     }
 
        }
     }
 
@@ -1495,7 +1495,7 @@ make_bcc_file (int dashstuff)
     if ((tfile = m_mktemp2(NULL, "bccs", NULL, &out)) == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
     if ((tfile = m_mktemp2(NULL, "bccs", NULL, &out)) == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
-    strncpy (bccfil, tfile, sizeof(bccfil));
+    strncpy (bccfil, tfile, sizeof(bccfil) - 1);
 
     fprintf (out, "From: %s\n", fullfrom);
     fprintf (out, "Date: %s\n", dtime (&tclock, 0));
 
     fprintf (out, "From: %s\n", fullfrom);
     fprintf (out, "Date: %s\n", dtime (&tclock, 0));
@@ -1878,7 +1878,7 @@ do_an_address (struct mailname *lp, int talk)
        case LOCALHOST: 
            mbox = lp->m_mbox;
            host = lp->m_host;
        case LOCALHOST: 
            mbox = lp->m_mbox;
            host = lp->m_host;
-           strncpy (addr, mbox, sizeof(addr));
+           strncpy (addr, mbox, sizeof(addr) - 1);
            break;
 
        case UUCPHOST: 
            break;
 
        case UUCPHOST: 
index b6594a4fa19def729a1c60acb6aee321af828d1b..c6698865d7ad916a9809866aa19d65384b7385be 100644 (file)
@@ -171,7 +171,7 @@ main (int argc, char **argv)
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
-    strncpy (tmpfil, tfile, sizeof(tmpfil));
+    strncpy (tmpfil, tfile, sizeof(tmpfil) - 1);
 
     cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
     fseek (fp, 0L, SEEK_SET);
 
     cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
     fseek (fp, 0L, SEEK_SET);
@@ -179,7 +179,7 @@ main (int argc, char **argv)
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
-    strncpy (drft, tfile, sizeof(tmpfil));
+    strncpy (drft, tfile, sizeof(drft) - 1);
 
     rcvdistout (fp, form, addrs);
     fclose (fp);
 
     rcvdistout (fp, form, addrs);
     fclose (fp);
index bbc1bae4369d3a3923684e9ddbdb0832e6c49c3d..ab4cf9e2da4d8a282577de146f753f7d2e4d5f6b 100644 (file)
@@ -216,7 +216,7 @@ main (int argc, char **argv)
        app_msgarg(&msgs, "cur");
     if (!folder)
        folder = getfolder (1);
        app_msgarg(&msgs, "cur");
     if (!folder)
        folder = getfolder (1);
-    strncpy (maildir, m_maildir (folder), sizeof(maildir));
+    strncpy (maildir, m_maildir (folder), sizeof(maildir) - 1);
 
     if (chdir (maildir) == NOTOK)
        adios (maildir, "unable to change directory to");
 
     if (chdir (maildir) == NOTOK)
        adios (maildir, "unable to change directory to");
@@ -311,7 +311,7 @@ opnfolds (struct msgs *src_folder, struct st_fold *folders, int nfolders)
        if (chdir (m_maildir ("")) < 0) {
            advise (m_maildir (""), "chdir");
        }
        if (chdir (m_maildir ("")) < 0) {
            advise (m_maildir (""), "chdir");
        }
-       strncpy (nmaildir, m_maildir (fp->f_name), sizeof(nmaildir));
+       strncpy (nmaildir, m_maildir (fp->f_name), sizeof(nmaildir) - 1);
 
        /*
         * Null src_folder indicates that we are refiling a file to
 
        /*
         * Null src_folder indicates that we are refiling a file to
index 6caa5e0d78fc7149f74059a436651711622b3668..0563c0a061b4b09d27ca4c617025739f7485f541 100644 (file)
@@ -383,7 +383,7 @@ main (int argc, char **argv)
 try_it_again:
 
     strncpy (drft, buildsw ? m_maildir ("reply")
 try_it_again:
 
     strncpy (drft, buildsw ? m_maildir ("reply")
-                         : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft));
+             : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft) - 1);
 
     /* Check if a draft exists */
     if (!buildsw && stat (drft, &st) != NOTOK) {
 
     /* Check if a draft exists */
     if (!buildsw && stat (drft, &st) != NOTOK) {
index 37e7162f4843364917e3a6d46b29631e603ab3c3..ee4abae874f2ce183a33f6c587425eaf10fbdc4f 100644 (file)
--- a/uip/rmf.c
+++ b/uip/rmf.c
@@ -119,9 +119,9 @@ main (int argc, char **argv)
        if (cp > newfolder)
            *cp = '\0';
        else
        if (cp > newfolder)
            *cp = '\0';
        else
-           strncpy (newfolder, getfolder(0), sizeof(newfolder));
+           strncpy (newfolder, getfolder(0), sizeof(newfolder) - 1);
     } else {
     } else {
-       strncpy (newfolder, getfolder(0), sizeof(newfolder));
+       strncpy (newfolder, getfolder(0), sizeof(newfolder) - 1);
     }
 
     if (interactive) {
     }
 
     if (interactive) {
index c7d788fdc490da8daaca9d9301fafe4d3077d0ec..628b99d2be7c385a640a8f70df2bbb82a74017be 100644 (file)
@@ -139,7 +139,8 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
            if (cp == NULL) {
                die("unable to create temporary file");
            }
            if (cp == NULL) {
                die("unable to create temporary file");
            }
-           if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
+           if (rename (drft, strncpy(file, cp, sizeof(file) - 1)) ==
+               NOTOK)
                adios (file, "unable to rename %s to", drft);
            drft = file;
        }
                adios (file, "unable to rename %s to", drft);
            drft = file;
        }
@@ -173,7 +174,7 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
        /* rename the original draft */
        if (rename_drft && status == OK &&
                rename (drft, strncpy (buffer, m_backup (drft),
        /* rename the original draft */
        if (rename_drft && status == OK &&
                rename (drft, strncpy (buffer, m_backup (drft),
-                                sizeof(buffer))) == NOTOK)
+                                sizeof(buffer) - 1)) == NOTOK)
            advise (buffer, "unable to rename %s to", drft);
        break;
 
            advise (buffer, "unable to rename %s to", drft);
        break;
 
@@ -324,7 +325,8 @@ alert (char *file, int out)
                    if (write (out, buf, strlen (buf)) < 0) {
                        advise (file, "write");
                    }
                    if (write (out, buf, strlen (buf)) < 0) {
                        advise (file, "write");
                    }
-                   if (rename (file, strncpy (buf, m_backup (file), sizeof(buf))) == NOTOK)
+                   if (rename (file, strncpy (buf, m_backup (file),
+                                              sizeof(buf) - 1)) == NOTOK)
                        admonish (buf, "unable to rename %s to", file);
                }
            }
                        admonish (buf, "unable to rename %s to", file);
                }
            }
index c86f2ceea80ba91a632c6ecc0c313a858523a824..bb500877931e6fa30296e3858ddbfc693663e3c3 100644 (file)
@@ -1038,7 +1038,7 @@ usr_folder (int fd, char *string)
 
     /* get folder name ready */
     if (*string == '+')
 
     /* get folder name ready */
     if (*string == '+')
-       strncpy(folder, string, sizeof(folder));
+       strncpy(folder, string, sizeof(folder) - 1);
     else
        snprintf(folder, sizeof(folder), "+%s", string);
 
     else
        snprintf(folder, sizeof(folder), "+%s", string);
 
@@ -1179,7 +1179,7 @@ get_sender (char *envelope, char **sender)
     }
 
     i = LEN("From ");
     }
 
     i = LEN("From ");
-    strncpy (buffer, envelope + i, sizeof(buffer));
+    strncpy (buffer, envelope + i, sizeof(buffer) - 1);
     if ((cp = strchr(buffer, '\n'))) {
        *cp = 0;
        cp -= 24;
     if ((cp = strchr(buffer, '\n'))) {
        *cp = 0;
        cp -= 24;
@@ -1317,7 +1317,7 @@ trim (char *cp)
        return NULL;
 
     /* copy string into temp buffer */
        return NULL;
 
     /* copy string into temp buffer */
-    strncpy (buffer, cp, sizeof(buffer));
+    strncpy (buffer, cp, sizeof(buffer) - 1);
     bp = buffer;
 
     /* skip over leading whitespace */
     bp = buffer;
 
     /* skip over leading whitespace */
index 2ba5c8e9ea676c8e2ab4dffb7393a85c0a913fac..4543631e13c3d5670cf3ac87ad580bffed08f033 100644 (file)
@@ -534,7 +534,7 @@ rename_chain (struct msgs *mp, struct smsg **mlist, int msg, int endmsg)
        mlist[msg] = NULL;
        old = smsgs[nxt].s_msg;
        new = smsgs[msg].s_msg;
        mlist[msg] = NULL;
        old = smsgs[nxt].s_msg;
        new = smsgs[msg].s_msg;
-       strncpy (oldname, m_name (old), sizeof(oldname));
+       strncpy (oldname, m_name (old), sizeof(oldname) - 1);
        newname = m_name (new);
        if (verbose)
            printf ("message %d becomes message %d\n", old, new);
        newname = m_name (new);
        if (verbose)
            printf ("message %d becomes message %d\n", old, new);
@@ -568,7 +568,7 @@ rename_msgs (struct msgs *mp, struct smsg **mlist)
     char newbuf[PATH_MAX + 1];
     struct smsg *sp;
 
     char newbuf[PATH_MAX + 1];
     struct smsg *sp;
 
-    strncpy (tmpfil, m_name (mp->hghmsg + 1), sizeof(tmpfil));
+    strncpy (tmpfil, m_name (mp->hghmsg + 1), sizeof(tmpfil) - 1);
 
     for (i = 0; i < nmsgs; i++) {
        if (! (sp = mlist[i]))
 
     for (i = 0; i < nmsgs; i++) {
        if (! (sp = mlist[i]))
@@ -585,7 +585,7 @@ rename_msgs (struct msgs *mp, struct smsg **mlist)
         */
        old = smsgs[j].s_msg;
        new = smsgs[i].s_msg;
         */
        old = smsgs[j].s_msg;
        new = smsgs[i].s_msg;
-       strncpy (f1, m_name (old), sizeof(f1));
+       strncpy (f1, m_name (old), sizeof(f1) - 1);
 
        if (verbose)
            printf ("renaming message chain from %d to %d\n", old, new);
 
        if (verbose)
            printf ("renaming message chain from %d to %d\n", old, new);
index fb60ec30dc4e6eeb2bce9b30a960c1ce864ee9c5..8bfb91d0099911a7d1cdb54d2cc2ce76c07ce64c 100644 (file)
@@ -155,7 +155,7 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw,
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
        die("unable to create temporary file in %s", get_temp_dir());
     }
-    strncpy (tmpfil, tfile, sizeof(tmpfil));
+    strncpy (tmpfil, tfile, sizeof(tmpfil) - 1);
 
     if (!strchr(mailsw, '@'))
        mailsw = concat (mailsw, "@", LocalName (0), NULL);
 
     if (!strchr(mailsw, '@'))
        mailsw = concat (mailsw, "@", LocalName (0), NULL);
index 9b71876bc1d97c306f1cb798d160c3ab0f3c6d46..7f28f34a18580b9698e1d9272d13a8fffcca9a01 100644 (file)
@@ -702,7 +702,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
 
     if (altmsg) {
        if (mp == NULL || *altmsg == '/' || cwd == NULL)
 
     if (altmsg) {
        if (mp == NULL || *altmsg == '/' || cwd == NULL)
-           strncpy (altpath, altmsg, sizeof(altpath));
+           strncpy (altpath, altmsg, sizeof(altpath) - 1);
        else
            snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
        if (cwd == NULL)
        else
            snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
        if (cwd == NULL)