From: David Levine Date: Sun, 15 Mar 2020 21:14:36 +0000 (-0400) Subject: Subtracted 1 from size argument in some calls to strncpy(3). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/283d1d6f7d1e3ef16af638b4b943e2386330e68e?ds=sidebyside;hp=f8437b262c94ef12c57f6024aaaab73f7ae50cf8 Subtracted 1 from size argument in some calls to strncpy(3). 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. --- diff --git a/sbr/addrsbr.c b/sbr/addrsbr.c index af8ecd4d..2eb20b0b 100644 --- a/sbr/addrsbr.c +++ b/sbr/addrsbr.c @@ -100,7 +100,7 @@ getname (const char *addrs) return NULL; } - strncpy (adr, ap->text, sizeof(adr)); + strncpy (adr, ap->text, sizeof(adr) - 1); 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) - strncpy (err, ap->err, sizeof(err)); + strncpy (err, ap->err, sizeof(err) - 1); return adr; } diff --git a/sbr/folder_delmsgs.c b/sbr/folder_delmsgs.c index 533ab9ba..a385827b 100644 --- a/sbr/folder_delmsgs.c +++ b/sbr/folder_delmsgs.c @@ -124,7 +124,7 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook) } } 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; diff --git a/sbr/folder_pack.c b/sbr/folder_pack.c index ba84d1f7..7fdfcf85 100644 --- a/sbr/folder_pack.c +++ b/sbr/folder_pack.c @@ -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) { - 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); diff --git a/sbr/m_draft.c b/sbr/m_draft.c index 342f44f0..803ed750 100644 --- a/sbr/m_draft.c +++ b/sbr/m_draft.c @@ -45,7 +45,7 @@ m_draft (char *folder, char *msg, int use, int *isdf) 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); diff --git a/sbr/m_maildir.c b/sbr/m_maildir.c index 5edc9360..888b8d22 100644 --- a/sbr/m_maildir.c +++ b/sbr/m_maildir.c @@ -78,7 +78,7 @@ exmaildir (char *folder) && strcmp (folder, DOT) && strcmp (folder, DOTDOT) && !has_prefix(folder, PWD))) { - strncpy (mailfold, folder, sizeof(mailfold)); + strncpy (mailfold, folder, sizeof(mailfold) - 1); return mailfold; } diff --git a/sbr/makedir.c b/sbr/makedir.c index 12305537..3bbfb686 100644 --- a/sbr/makedir.c +++ b/sbr/makedir.c @@ -44,7 +44,7 @@ makedir (const char *dir) 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) { diff --git a/sbr/mts.c b/sbr/mts.c index 4c95f481..5f4e3676 100644 --- 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) { - strncpy (buf, localname, sizeof(buffer0)); + strncpy (buf, localname, sizeof(buffer0) - 1); } 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) { - strncpy (buffer, systemname, sizeof(buffer)); + strncpy (buffer, systemname, sizeof(buffer) - 1); return buffer; } @@ -409,7 +409,7 @@ getuserinfo (void) 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 && diff --git a/test/getfullname.c b/test/getfullname.c index 14f45423..91777c39 100644 --- a/test/getfullname.c +++ b/test/getfullname.c @@ -36,7 +36,7 @@ main(int argc, char *argv[]) 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. diff --git a/uip/annosbr.c b/uip/annosbr.c index 8b0c8843..dbd769a5 100644 --- a/uip/annosbr.c +++ b/uip/annosbr.c @@ -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"); } - strncpy (tmpfil, cp, sizeof(tmpfil)); + strncpy (tmpfil, cp, sizeof(tmpfil) - 1); 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 { - 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 */ diff --git a/uip/burst.c b/uip/burst.c index 289ce819..b80d9ce9 100644 --- a/uip/burst.c +++ b/uip/burst.c @@ -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--) { - 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); @@ -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()); } - 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); @@ -496,7 +496,7 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, 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); diff --git a/uip/comp.c b/uip/comp.c index 69210f81..c16e89d0 100644 --- a/uip/comp.c +++ b/uip/comp.c @@ -340,7 +340,7 @@ main (int argc, char **argv) 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 diff --git a/uip/dist.c b/uip/dist.c index e6720ae7..1c2b596a 100644 --- a/uip/dist.c +++ b/uip/dist.c @@ -253,7 +253,7 @@ main (int argc, char **argv) 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) { diff --git a/uip/distsbr.c b/uip/distsbr.c index 4df836ef..f830bc9b 100644 --- a/uip/distsbr.c +++ b/uip/distsbr.c @@ -156,7 +156,7 @@ ready_msg (char *msgnam) 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"); @@ -187,7 +187,7 @@ ready_msg (char *msgnam) 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"); diff --git a/uip/flist.c b/uip/flist.c index aedfd884..17dd6721 100644 --- a/uip/flist.c +++ b/uip/flist.c @@ -234,7 +234,7 @@ main(int argc, char **argv) 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 (""); @@ -316,7 +316,7 @@ ScanFolders(void) 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 */ diff --git a/uip/folder.c b/uip/folder.c index 8ab6528b..6706ef87 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -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); - strncpy (folder, FENDNULL(cp), sizeof(folder)); + strncpy (folder, FENDNULL(cp), sizeof(folder) - 1); 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 */ @@ -379,7 +379,8 @@ main (int argc, char **argv) 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 diff --git a/uip/forw.c b/uip/forw.c index 5194a5aa..530e61cd 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -339,7 +339,7 @@ main (int argc, char **argv) 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) { diff --git a/uip/forwsbr.c b/uip/forwsbr.c index 1b6a92cb..2e098bd5 100644 --- a/uip/forwsbr.c +++ b/uip/forwsbr.c @@ -184,7 +184,7 @@ finished: 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"); diff --git a/uip/mhbuild.c b/uip/mhbuild.c index 48f7e4b4..66860eee 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -302,7 +302,7 @@ main (int argc, char **argv) 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) { @@ -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"); } - strncpy(outfile, cp, sizeof(outfile)); + strncpy(outfile, cp, sizeof(outfile) - 1); /* output the message */ output_message_fp (ct, fp_out, outfile); diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index b96e63ac..6795025f 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -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] == '<')) { - strncpy (content, buf + 2, sizeof(content)); + strncpy (content, buf + 2, sizeof(content) - 1); 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; - 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; diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index ffb39b9c..ade7e1c2 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -610,7 +610,7 @@ mhl_format (char *file, int length, int width) } parptr = bp; - strncpy (name, parse(), sizeof(name)); + strncpy (name, parse(), sizeof(name) - 1); switch (*parptr) { case '\0': case ',': @@ -725,7 +725,7 @@ evalvar (struct mcomp *c1) 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)) diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index cd53d145..a39459ef 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -379,7 +379,7 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked, struct format * } if (cracked) { - strncpy (buffer, cp, sizeof(buffer)); + strncpy (buffer, cp, sizeof(buffer) - 1); goto got_command; } @@ -1041,7 +1041,7 @@ raw: 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); } diff --git a/uip/mhstoresbr.c b/uip/mhstoresbr.c index 131650be..64b69bc0 100644 --- a/uip/mhstoresbr.c +++ b/uip/mhstoresbr.c @@ -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') { - strncpy (buffer, cp, buflen); + strncpy (buffer, cp, buflen - 1); return 0; } diff --git a/uip/popsbr.c b/uip/popsbr.c index 3df93bd9..c1d520e9 100644 --- a/uip/popsbr.c +++ b/uip/popsbr.c @@ -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; - strncpy(server_mechs, response + 5, server_mechs_size); + strncpy(server_mechs, response + 5, server_mechs_size - 1); } } diff --git a/uip/post.c b/uip/post.c index 246f5670..5243d55a 100644 --- a/uip/post.c +++ b/uip/post.c @@ -631,7 +631,7 @@ main (int argc, char **argv) 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()); } - 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)); @@ -1878,7 +1878,7 @@ do_an_address (struct mailname *lp, int talk) case LOCALHOST: mbox = lp->m_mbox; host = lp->m_host; - strncpy (addr, mbox, sizeof(addr)); + strncpy (addr, mbox, sizeof(addr) - 1); break; case UUCPHOST: diff --git a/uip/rcvdist.c b/uip/rcvdist.c index b6594a4f..c6698865 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -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()); } - strncpy (tmpfil, tfile, sizeof(tmpfil)); + strncpy (tmpfil, tfile, sizeof(tmpfil) - 1); 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()); } - strncpy (drft, tfile, sizeof(tmpfil)); + strncpy (drft, tfile, sizeof(drft) - 1); rcvdistout (fp, form, addrs); fclose (fp); diff --git a/uip/refile.c b/uip/refile.c index bbc1bae4..ab4cf9e2 100644 --- a/uip/refile.c +++ b/uip/refile.c @@ -216,7 +216,7 @@ main (int argc, char **argv) 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"); @@ -311,7 +311,7 @@ opnfolds (struct msgs *src_folder, struct st_fold *folders, int nfolders) 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 diff --git a/uip/repl.c b/uip/repl.c index 6caa5e0d..0563c0a0 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -383,7 +383,7 @@ main (int argc, char **argv) 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) { diff --git a/uip/rmf.c b/uip/rmf.c index 37e7162f..ee4abae8 100644 --- a/uip/rmf.c +++ b/uip/rmf.c @@ -119,9 +119,9 @@ main (int argc, char **argv) if (cp > newfolder) *cp = '\0'; else - strncpy (newfolder, getfolder(0), sizeof(newfolder)); + strncpy (newfolder, getfolder(0), sizeof(newfolder) - 1); } else { - strncpy (newfolder, getfolder(0), sizeof(newfolder)); + strncpy (newfolder, getfolder(0), sizeof(newfolder) - 1); } if (interactive) { diff --git a/uip/sendsbr.c b/uip/sendsbr.c index c7d788fd..628b99d2 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -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 (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; } @@ -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), - sizeof(buffer))) == NOTOK) + sizeof(buffer) - 1)) == NOTOK) 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 (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); } } diff --git a/uip/slocal.c b/uip/slocal.c index c86f2cee..bb500877 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -1038,7 +1038,7 @@ usr_folder (int fd, char *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); @@ -1179,7 +1179,7 @@ get_sender (char *envelope, char **sender) } 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; @@ -1317,7 +1317,7 @@ trim (char *cp) return NULL; /* copy string into temp buffer */ - strncpy (buffer, cp, sizeof(buffer)); + strncpy (buffer, cp, sizeof(buffer) - 1); bp = buffer; /* skip over leading whitespace */ diff --git a/uip/sortm.c b/uip/sortm.c index 2ba5c8e9..4543631e 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -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; - 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); @@ -568,7 +568,7 @@ rename_msgs (struct msgs *mp, struct smsg **mlist) 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])) @@ -585,7 +585,7 @@ rename_msgs (struct msgs *mp, struct smsg **mlist) */ 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); diff --git a/uip/viamail.c b/uip/viamail.c index fb60ec30..8bfb91d0 100644 --- a/uip/viamail.c +++ b/uip/viamail.c @@ -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()); } - strncpy (tmpfil, tfile, sizeof(tmpfil)); + strncpy (tmpfil, tfile, sizeof(tmpfil) - 1); if (!strchr(mailsw, '@')) mailsw = concat (mailsw, "@", LocalName (0), NULL); diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 9b71876b..7f28f34a 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -702,7 +702,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp, 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)