From: Ralph Corderoy Date: Sun, 7 May 2017 12:03:01 +0000 (+0100) Subject: Make many m_getfld() buffer parameters NMH_BUFSIZ big. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/a23477eb9bd7d1af5f66a171041bf72af932488e?ds=inline Make many m_getfld() buffer parameters NMH_BUFSIZ big. 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. --- diff --git a/sbr/readconfig.c b/sbr/readconfig.c index 21b40c73..53f5c353 100644 --- a/sbr/readconfig.c +++ b/sbr/readconfig.c @@ -44,7 +44,7 @@ readconfig (struct node **npp, FILE *ib, const char *file, int ctx) { 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; diff --git a/sbr/seq_read.c b/sbr/seq_read.c index d859a34e..c7f1beac 100644 --- a/sbr/seq_read.c +++ b/sbr/seq_read.c @@ -60,7 +60,7 @@ seq_public (struct msgs *mp, int lockflag, int *failed_to_lock) { 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; diff --git a/test/bad-input/test-header b/test/bad-input/test-header index ef7b3992..0148db57 100755 --- a/test/bad-input/test-header +++ b/test/bad-input/test-header @@ -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" -# 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" <"$expected" <"$expected_err" <"$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 diff --git a/uip/distsbr.c b/uip/distsbr.c index 6fc77372..640b30a5 100644 --- a/uip/distsbr.c +++ b/uip/distsbr.c @@ -27,7 +27,7 @@ distout (char *drft, char *msgnam, char *backup) { 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; @@ -124,7 +124,7 @@ static void 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; diff --git a/uip/forwsbr.c b/uip/forwsbr.c index 2a7347ab..f6104d23 100644 --- a/uip/forwsbr.c +++ b/uip/forwsbr.c @@ -16,7 +16,7 @@ * 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) /* diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index f26c81be..62df410d 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -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; - char buf[BUFSIZ], name[NAMESZ]; + char buf[NMH_BUFSIZ], name[NAMESZ]; char *cp, *np, *vp; struct multipart *m; struct part **pp; diff --git a/uip/mhcachesbr.c b/uip/mhcachesbr.c index 905dfa7c..fe4f4790 100644 --- a/uip/mhcachesbr.c +++ b/uip/mhcachesbr.c @@ -366,7 +366,7 @@ static int 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; diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index cb6080b6..6dd1850d 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -935,7 +935,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) { 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(); diff --git a/uip/mhparse.c b/uip/mhparse.c index 79ef6968..983324e7 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -298,7 +298,7 @@ static CT 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; diff --git a/uip/new.c b/uip/new.c index 134f88ed..8e3c3505 100644 --- 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 name[NAMESZ], field[BUFSIZ]; + char name[NAMESZ], field[NMH_BUFSIZ]; char *cp; char *msgnums = NULL, *this_msgnums, *old_msgnums; int failed_to_lock = 0; diff --git a/uip/picksbr.c b/uip/picksbr.c index c0799bd9..21cdb2ca 100644 --- a/uip/picksbr.c +++ b/uip/picksbr.c @@ -930,7 +930,7 @@ plist { 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); diff --git a/uip/post.c b/uip/post.c index c0d10f66..1323e19d 100644 --- a/uip/post.c +++ b/uip/post.c @@ -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; - 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; diff --git a/uip/prompter.c b/uip/prompter.c index 630ef860..35092296 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -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; - char *killp = NULL, name[NAMESZ], field[BUFSIZ]; + char *killp = NULL, name[NAMESZ], field[NMH_BUFSIZ]; char buffer[BUFSIZ]; char **arguments, **argp; FILE *in, *out; diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 7fd59ec2..b013c85d 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -144,7 +144,7 @@ main (int argc, char **argv) /* very similar to routine in replsbr.c */ -#define SBUFSIZ 256 +#define SBUFSIZ NMH_BUFSIZ static int outputlinelen = OUTPUTLINELEN; diff --git a/uip/replsbr.c b/uip/replsbr.c index 9e3183e4..2cb06ece 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -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. */ -#define SBUFSIZ 256 +#define SBUFSIZ NMH_BUFSIZ static char *addrcomps[] = { "from", diff --git a/uip/scansbr.c b/uip/scansbr.c index ce29fa8b..c7979b64 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -19,7 +19,7 @@ * 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 */ diff --git a/uip/sendsbr.c b/uip/sendsbr.c index 792ac12f..2de5c90f 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -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; - 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; diff --git a/uip/show.c b/uip/show.c index 0e7e7911..8ff381fb 100644 --- a/uip/show.c +++ b/uip/show.c @@ -367,7 +367,7 @@ is_nontext (char *msgnam) { 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; diff --git a/uip/slocal.c b/uip/slocal.c index 34c615a7..1e044f52 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -708,7 +708,7 @@ parse (int fd) 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; @@ -1407,7 +1407,7 @@ static int 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; diff --git a/uip/sortm.c b/uip/sortm.c index 6c436ba7..8fa9e5b5 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -335,7 +335,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg) { 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; diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 111a7067..6c82e24d 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -1311,7 +1311,7 @@ checkmimeheader (char *drft) { 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) {