X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/ef0725fd97369e801a56febfdb7a6ec2eaff73c8..4829d096feb337a55e2b866adb19acab9617b071:/uip/mhbuildsbr.c diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 04dc4a7b..6670e711 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -190,9 +190,20 @@ build_mime (char *infile, int autobuild, int dist, int directives, case FLDPLUS: compnum++; - /* abort if draft has Mime-Version or C-T-E header field */ - if (strcasecmp (name, VRSN_FIELD) == 0 || - strcasecmp (name, ENCODING_FIELD) == 0) { + /* + * If we are running with autobuild set, then silently + * exit if we find a MIME-Version header. For any other MIME + * header, return an error. + * + * RFC 2045, Section 9 says that any valid MIME header should + * start with "Content-", so we will match on that rather than + * enumerate all current MIME headers. + * + * Because the headers could be in any order, just check for + * MIME-Version here; check for Content-* later. + */ + + if (strcasecmp (name, VRSN_FIELD) == 0) { if (autobuild) { fclose(in); free (ct); @@ -201,15 +212,6 @@ build_mime (char *infile, int autobuild, int dist, int directives, die("draft shouldn't contain %s: field", name); } - /* ignore any Content-Type fields in the header */ - if (!strcasecmp (name, TYPE_FIELD)) { - while (state == FLDPLUS) { - bufsz = sizeof buf; - state = m_getfld2(&gstate, name, buf, &bufsz); - } - goto finish_field; - } - /* get copies of the buffers */ np = mh_xstrdup(name); vp = mh_xstrdup(buf); @@ -365,6 +367,16 @@ finish_field: } m_getfld_state_destroy (&gstate); + /* + * If we see any Content-* headers at this point, it is an error. + */ + + for (hp = ct->c_first_hf; hp != NULL; hp = hp->next) { + if (uprf (hp->name, "Content-")) { + die ("draft shouldn't contain %s: field", hp->name); + } + } + if (header_encoding != CE_8BIT) { /* * Iterate through the list of headers and call the function to MIME-ify @@ -662,7 +674,7 @@ static int user_content (FILE *in, char *buf, CT *ctp, const char *infilename) { int extrnal, vrsn; - char *cp, **ap; + char *cp, *const *ap; char buffer[NMH_BUFSIZ]; struct multipart *m; struct part **pp; @@ -714,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; } @@ -723,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;