]> diplodocus.org Git - nmh/commitdiff
Make many m_getfld() buffer parameters NMH_BUFSIZ big.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 7 May 2017 12:03:01 +0000 (13:03 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 7 May 2017 12:03:01 +0000 (13:03 +0100)
char arrays were often stdio.h's BUFSIZ large, and that's 8192 with here
with glibc 2.25-1 on Linux x86_64, so using NMH_BUFSIZ is no different
as that's max(BUFSIZ, 8192).  But some were 256 or 512 with a local
SBUFSIZ macro and they caused scan(1) to truncate a field, or pick(1) to
not spot text because the field was truncated.

Delete bad-input/test-header's test for m_getfld()'s detection for a
header without a colon that's under the header-length NAMESZ limit, but
longer than the passed in buffer.  This no longer happens in scan as the
buffer is larger than the longest allowed header.

21 files changed:
sbr/readconfig.c
sbr/seq_read.c
test/bad-input/test-header
uip/distsbr.c
uip/forwsbr.c
uip/mhbuildsbr.c
uip/mhcachesbr.c
uip/mhlsbr.c
uip/mhparse.c
uip/new.c
uip/picksbr.c
uip/post.c
uip/prompter.c
uip/rcvdist.c
uip/replsbr.c
uip/scansbr.c
uip/sendsbr.c
uip/show.c
uip/slocal.c
uip/sortm.c
uip/whatnowsbr.c

index 21b40c7..53f5c35 100644 (file)
@@ -44,7 +44,7 @@ readconfig (struct node **npp, FILE *ib, const char *file, int ctx)
 {
     int state;
     char *cp;
 {
     int state;
     char *cp;
-    char name[NAMESZ], field[BUFSIZ];
+    char name[NAMESZ], field[NMH_BUFSIZ];
     struct node *np;
     struct procstr *ps;
     m_getfld_state_t gstate = 0;
     struct node *np;
     struct procstr *ps;
     m_getfld_state_t gstate = 0;
index d859a34..c7f1bea 100644 (file)
@@ -60,7 +60,7 @@ seq_public (struct msgs *mp, int lockflag, int *failed_to_lock)
 {
     int state;
     char *cp, seqfile[PATH_MAX];
 {
     int state;
     char *cp, seqfile[PATH_MAX];
-    char name[NAMESZ], field[BUFSIZ];
+    char name[NAMESZ], field[NMH_BUFSIZ];
     FILE *fp;
     m_getfld_state_t gstate = 0;
 
     FILE *fp;
     m_getfld_state_t gstate = 0;
 
index ef7b399..0148db5 100755 (executable)
@@ -122,29 +122,5 @@ verify_string_in_file 'exceeds 997' "$actual_err"
 verify_string_in_file '??Format error (message 13) in component 2' "$actual_err"
 rm -f "$actual_err"
 
 verify_string_in_file '??Format error (message 13) in component 2' "$actual_err"
 rm -f "$actual_err"
 
-# check m_getfld() handling of long header field name without a colon
-start_test 'm_getfld() handling of long header field name without a colon'
-msgfile="$MH_TEST_DIR/Mail/inbox/14"
-cat >"$msgfile" <<EOF
-Date: Thu, 17 Jan 2013 19:33:46 -0600
-If a header field name has at least 512 characters without a newline or colon, it will raise a format error in m_getfld().  Here is a test of that.  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
-
-Test
-
-
-EOF
-cat >"$expected" <<EOF
-  14  01/17  
-EOF
-cat >"$expected_err" <<EOF
-scan: eol encountered in field "If a header field name has at least 512 characters without a newline or colon, it will raise a format error in m_getfld().  Here is a test of that.  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
-??Format error (message 14) in component 2
-EOF
-
-run_prog scan -width 13 last >"$actual" 2>"$actual_err"
-check "$expected" "$actual" : m_getfld with long header, no colon output
-check "$expected_err" "$actual_err" : m_getfld with long header, no colon error
-
-
 finish_test
 exit $failed
 finish_test
 exit $failed
index 6fc7737..640b30a 100644 (file)
@@ -27,7 +27,7 @@ distout (char *drft, char *msgnam, char *backup)
 {
     int state;
     char *dp, *resent;
 {
     int state;
     char *dp, *resent;
-    char name[NAMESZ], buffer[BUFSIZ];
+    char name[NAMESZ], buffer[NMH_BUFSIZ];
     FILE *ifp, *ofp;
     m_getfld_state_t gstate = 0;
 
     FILE *ifp, *ofp;
     m_getfld_state_t gstate = 0;
 
@@ -124,7 +124,7 @@ static void
 ready_msg (char *msgnam)
 {
     int state, out;
 ready_msg (char *msgnam)
 {
     int state, out;
-    char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
+    char name[NAMESZ], buffer[NMH_BUFSIZ], tmpfil[BUFSIZ];
     FILE *ifp, *ofp;
     char *cp = NULL;
     m_getfld_state_t gstate = 0;
     FILE *ifp, *ofp;
     char *cp = NULL;
     m_getfld_state_t gstate = 0;
index 2a7347a..f6104d2 100644 (file)
@@ -16,7 +16,7 @@
  * in reasonable chunks but not enough to slurp in the whole message
  */
 
  * in reasonable chunks but not enough to slurp in the whole message
  */
 
-static char msgbuf[256];
+static char msgbuf[NMH_BUFSIZ];
 #define COMPFREE(c) mh_xfree(c->c_text)
 
 /*
 #define COMPFREE(c) mh_xfree(c->c_text)
 
 /*
index f26c81b..62df410 100644 (file)
@@ -131,7 +131,7 @@ build_mime (char *infile, int autobuild, int dist, int directives,
            int header_encoding, size_t maxunencoded, int verbose)
 {
     int        compnum, state;
            int header_encoding, size_t maxunencoded, int verbose)
 {
     int        compnum, state;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     char *cp, *np, *vp;
     struct multipart *m;
     struct part **pp;
     char *cp, *np, *vp;
     struct multipart *m;
     struct part **pp;
index 905dfa7..fe4f479 100644 (file)
@@ -366,7 +366,7 @@ static int
 find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen)
 {
     int        state;
 find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen)
 {
     int        state;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     FILE *fp;
     m_getfld_state_t gstate = 0;
     int failed_to_lock = 0;
     FILE *fp;
     m_getfld_state_t gstate = 0;
     int failed_to_lock = 0;
index cb6080b..6dd1850 100644 (file)
@@ -935,7 +935,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec)
 {
     int state, bucket;
     struct mcomp *c1, *c2, *c3;
 {
     int state, bucket;
     struct mcomp *c1, *c2, *c3;
-    char **ip, name[NAMESZ], buf[BUFSIZ];
+    char **ip, name[NAMESZ], buf[NMH_BUFSIZ];
     m_getfld_state_t gstate = 0;
 
     compile_filterargs();
     m_getfld_state_t gstate = 0;
 
     compile_filterargs();
index 79ef696..983324e 100644 (file)
@@ -298,7 +298,7 @@ static CT
 get_content (FILE *in, char *file, int toplevel)
 {
     int compnum, state;
 get_content (FILE *in, char *file, int toplevel)
 {
     int compnum, state;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     char *np, *vp;
     CT ct;
     HF hp;
     char *np, *vp;
     CT ct;
     HF hp;
index 134f88e..8e3c350 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -96,7 +96,7 @@ get_msgnums(char *folder, char *sequences[])
     char *seqfile = NULL;
     FILE *fp;
     int state;
     char *seqfile = NULL;
     FILE *fp;
     int state;
-    char name[NAMESZ], field[BUFSIZ];
+    char name[NAMESZ], field[NMH_BUFSIZ];
     char *cp;
     char *msgnums = NULL, *this_msgnums, *old_msgnums;
     int failed_to_lock = 0;
     char *cp;
     char *msgnums = NULL, *this_msgnums, *old_msgnums;
     int failed_to_lock = 0;
index c0799bd..21cdb2c 100644 (file)
@@ -930,7 +930,7 @@ plist
 {
     int state;
     char *bp;
 {
     int state;
     char *bp;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     struct tws *tw;
     m_getfld_state_t gstate = 0;
     NMH_UNUSED (stop);
     struct tws *tw;
     m_getfld_state_t gstate = 0;
     NMH_UNUSED (stop);
index c0d10f6..1323e19 100644 (file)
@@ -318,7 +318,7 @@ main (int argc, char **argv)
     int noverify = 0;
     int eai = 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
     char *cp, *msg = NULL, **argp, **arguments, *envelope;
     int noverify = 0;
     int eai = 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
     char *cp, *msg = NULL, **argp, **arguments, *envelope;
-    char buf[BUFSIZ], name[NAMESZ], *auth_svc = NULL;
+    char buf[NMH_BUFSIZ], name[NAMESZ], *auth_svc = NULL;
     FILE *in, *out;
     m_getfld_state_t gstate = 0;
 
     FILE *in, *out;
     m_getfld_state_t gstate = 0;
 
index 630ef86..3509229 100644 (file)
@@ -69,7 +69,7 @@ main (int argc, char **argv)
     int body = 1, prepend = 1, rapid = 0;
     int doteof = 0, fdi, fdo, i, state;
     char *cp, *drft = NULL, *erasep = NULL;
     int body = 1, prepend = 1, rapid = 0;
     int doteof = 0, fdi, fdo, i, state;
     char *cp, *drft = NULL, *erasep = NULL;
-    char *killp = NULL, name[NAMESZ], field[BUFSIZ];
+    char *killp = NULL, name[NAMESZ], field[NMH_BUFSIZ];
     char buffer[BUFSIZ];
     char **arguments, **argp;
     FILE *in, *out;
     char buffer[BUFSIZ];
     char **arguments, **argp;
     FILE *in, *out;
index 7fd59ec..b013c85 100644 (file)
@@ -144,7 +144,7 @@ main (int argc, char **argv)
 
 /* very similar to routine in replsbr.c */
 
 
 /* very similar to routine in replsbr.c */
 
-#define        SBUFSIZ 256
+#define        SBUFSIZ NMH_BUFSIZ
 
 static int outputlinelen = OUTPUTLINELEN;
 
 
 static int outputlinelen = OUTPUTLINELEN;
 
index 9e3183e..2cb06ec 100644 (file)
@@ -31,7 +31,7 @@ static int nodupcheck = 0;            /* If set, no check for duplicates */
  * small enough so that we don't snarf the entire
  * message body when we're not going to use any of it.
  */
  * small enough so that we don't snarf the entire
  * message body when we're not going to use any of it.
  */
-#define SBUFSIZ 256            
+#define        SBUFSIZ NMH_BUFSIZ
 
 static char *addrcomps[] = {
     "from",
 
 static char *addrcomps[] = {
     "from",
index ce29fa8..c7979b6 100644 (file)
@@ -19,7 +19,7 @@
  * the entire message body when we're only going to display 30
  * characters of it.
  */
  * the entire message body when we're only going to display 30
  * characters of it.
  */
-#define SBUFSIZ 512
+#define SBUFSIZ NMH_BUFSIZ
 
 static struct format *fmt;
 static struct comp *datecomp;          /* pntr to "date" comp             */
 
 static struct format *fmt;
 static struct comp *datecomp;          /* pntr to "date" comp             */
index 792ac12..2de5c90 100644 (file)
@@ -189,7 +189,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
     int        compnum, nparts, partno, state, status;
     long pos, start;
     time_t clock;
     int        compnum, nparts, partno, state, status;
     long pos, start;
     time_t clock;
-    char *cp, *dp, buffer[BUFSIZ], msgid[BUFSIZ];
+    char *cp, *dp, buffer[NMH_BUFSIZ], msgid[BUFSIZ];
     char subject[BUFSIZ];
     char name[NAMESZ], partnum[BUFSIZ];
     FILE *in;
     char subject[BUFSIZ];
     char name[NAMESZ], partnum[BUFSIZ];
     FILE *in;
index 0e7e791..8ff381f 100644 (file)
@@ -367,7 +367,7 @@ is_nontext (char *msgnam)
 {
     int        result, state;
     char *bp, *dp, *cp;
 {
     int        result, state;
     char *bp, *dp, *cp;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     FILE *fp;
     m_getfld_state_t gstate = 0;
 
     FILE *fp;
     m_getfld_state_t gstate = 0;
 
index 34c615a..1e044f5 100644 (file)
@@ -708,7 +708,7 @@ parse (int fd)
     int i, state;
     int fd1;
     char *cp, *dp, *lp;
     int i, state;
     int fd1;
     char *cp, *dp, *lp;
-    char name[NAMESZ], field[BUFSIZ];
+    char name[NAMESZ], field[NMH_BUFSIZ];
     struct pair *p, *q;
     FILE  *in;
     m_getfld_state_t gstate = 0;
     struct pair *p, *q;
     FILE  *in;
     m_getfld_state_t gstate = 0;
@@ -1407,7 +1407,7 @@ static int
 suppress_duplicates (int fd, char *file)
 {
     int        fd1, lockfd, state, result;
 suppress_duplicates (int fd, char *file)
 {
     int        fd1, lockfd, state, result;
-    char *cp, buf[BUFSIZ], name[NAMESZ];
+    char *cp, buf[NMH_BUFSIZ], name[NAMESZ];
     datum key, value;
     DBM *db;
     FILE *in;
     datum key, value;
     DBM *db;
     FILE *in;
index 6c436ba..8fa9e5b 100644 (file)
@@ -335,7 +335,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg)
 {
     int state;
     int compnum;
 {
     int state;
     int compnum;
-    char *msgnam, buf[BUFSIZ], nam[NAMESZ];
+    char *msgnam, buf[NMH_BUFSIZ], nam[NAMESZ];
     struct tws *tw;
     char *datecomp = NULL, *subjcomp = NULL;
     FILE *in;
     struct tws *tw;
     char *datecomp = NULL, *subjcomp = NULL;
     FILE *in;
index 111a706..6c82e24 100644 (file)
@@ -1311,7 +1311,7 @@ checkmimeheader (char *drft)
 {
     FILE *f;
     m_getfld_state_t gstate = 0;
 {
     FILE *f;
     m_getfld_state_t gstate = 0;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     int state, retval = 0;
 
     if ((f = fopen(drft, "r")) == NULL) {
     int state, retval = 0;
 
     if ((f = fopen(drft, "r")) == NULL) {