X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/a219784d3963d335aeaf15eefa3b51b26537bcd3..a1dcc0bd9e1ffd90ef88cd19f8ff8197f541c8a8:/sbr/mf.c?ds=sidebyside diff --git a/sbr/mf.c b/sbr/mf.c index 37fcf7b9..fa281766 100644 --- a/sbr/mf.c +++ b/sbr/mf.c @@ -8,15 +8,12 @@ */ #include -#include -#include #include /* * static prototypes */ -static char *getcpy (char *); -static int isat (char *); +static int isat (const char *); static int parse_address (void); static int phrase (char *); static int route_addr (char *); @@ -26,27 +23,8 @@ static int route (char *); static int my_lex (char *); -static char * -getcpy (char *s) -{ - register char *p; - - if (!s) { -/* causes compiles to blow up because the symbol _cleanup is undefined - where did this ever come from? */ - /* _cleanup(); */ - abort(); - for(;;) - pause(); - } - p = mh_xmalloc ((size_t) (strlen (s) + 2)); - strcpy (p, s); - return p; -} - - int -isfrom(char *string) +isfrom(const char *string) { return (strncmp (string, "From ", 5) == 0 || strncmp (string, ">From ", 6) == 0); @@ -54,7 +32,7 @@ isfrom(char *string) int -lequal (char *a, char *b) +lequal (const char *a, const char *b) { for (; *a; a++, b++) if (*b == 0) @@ -73,7 +51,7 @@ lequal (char *a, char *b) static int -isat (char *p) +isat (const char *p) { return (strncmp (p, " AT ", 4) && strncmp (p, " At ", 4) @@ -87,7 +65,7 @@ isat (char *p) * getadrx() implements a partial 822-style address parser. The parser * is neither complete nor correct. It does however recognize nearly all * of the 822 address syntax. In addition it handles the majority of the - * 733 syntax as well. Most problems arise from trying to accomodate both. + * 733 syntax as well. Most problems arise from trying to accommodate both. * * In terms of 822, the route-specification in * @@ -196,11 +174,12 @@ static char adr[BUFSIZ]; static struct adrx adrxs2; +/* eai = Email Address Internationalization */ struct adrx * -getadrx (char *addrs) +getadrx (const char *addrs, int eai) { - register char *bp; - register struct adrx *adrxp = &adrxs2; + char *bp; + struct adrx *adrxp = &adrxs2; if (pers) free (pers); @@ -218,7 +197,7 @@ getadrx (char *addrs) err[0] = 0; if (dp == NULL) { - dp = cp = getcpy (addrs ? addrs : ""); + dp = cp = strdup (addrs ? addrs : ""); glevel = 0; } else @@ -252,6 +231,17 @@ getadrx (char *addrs) break; } + if (! eai) { + /* + * Reject the address if key fields contain 8bit characters + */ + + if (contains8bit(mbox, NULL) || contains8bit(host, NULL) || + contains8bit(path, NULL) || contains8bit(grp, NULL)) { + strcpy(err, "Address contains 8-bit characters"); + } + } + if (err[0]) for (;;) { switch (last_lex) { @@ -268,7 +258,7 @@ getadrx (char *addrs) while (isspace ((unsigned char) *ap)) ap++; if (cp) - sprintf (adr, "%.*s", (int)(cp - ap), ap); + snprintf(adr, sizeof adr, "%.*s", (int)(cp - ap), ap); else strcpy (adr, ap); bp = adr + strlen (adr) - 1; @@ -299,7 +289,7 @@ again: ; switch (my_lex (buffer)) { case LX_ATOM: case LX_QSTR: - pers = getcpy (buffer); + pers = strdup (buffer); break; case LX_SEMI: @@ -327,7 +317,7 @@ again: ; return OK; /* why be choosy? */ default: - sprintf (err, "illegal address construct (%s)", buffer); + snprintf(err, sizeof err, "illegal address construct (%s)", buffer); return NOTOK; } @@ -346,13 +336,13 @@ again: ; return NOTOK; if (last_lex == LX_RBRK) return OK; - sprintf (err, "missing right-bracket (%s)", buffer); + snprintf(err, sizeof err, "missing right-bracket (%s)", buffer); return NOTOK; case LX_COLN: get_group: ; if (glevel++ > 0) { - sprintf (err, "nested groups not allowed (%s)", pers); + snprintf(err, sizeof err, "nested groups not allowed (%s)", pers); return NOTOK; } grp = add (": ", pers); @@ -381,7 +371,7 @@ again: ; goto more_phrase; default: - sprintf (err, "no mailbox in address, only a phrase (%s%s)", + snprintf(err, sizeof err, "no mailbox in address, only a phrase (%s%s)", pers, buffer); return NOTOK; } @@ -417,7 +407,7 @@ again: ; return OK; default: - sprintf (err, "junk after local@domain (%s)", buffer); + snprintf(err, sizeof err, "junk after local@domain (%s)", buffer); return NOTOK; } @@ -434,7 +424,7 @@ again: ; return OK; default: - sprintf (err, "missing mailbox (%s)", buffer); + snprintf(err, sizeof err, "missing mailbox (%s)", buffer); return NOTOK; } } @@ -459,7 +449,7 @@ phrase (char *buffer) static int route_addr (char *buffer) { - register char *pp = cp; + char *pp = cp; if (my_lex (buffer) == LX_AT) { if (route (buffer) == NOTOK) @@ -482,7 +472,7 @@ route_addr (char *buffer) return OK; default: - sprintf (err, "no at-sign after local-part (%s)", buffer); + snprintf(err, sizeof err, "no at-sign after local-part (%s)", buffer); return NOTOK; } } @@ -501,7 +491,7 @@ local_part (char *buffer) break; default: - sprintf (err, "no mailbox in local-part (%s)", buffer); + snprintf(err, sizeof err, "no mailbox in local-part (%s)", buffer); return NOTOK; } @@ -528,7 +518,7 @@ domain (char *buffer) break; default: - sprintf (err, "no sub-domain in domain-part of address (%s)", buffer); + snprintf(err, sizeof err, "no sub-domain in domain-part of address (%s)", buffer); return NOTOK; } @@ -553,7 +543,7 @@ domain (char *buffer) static int route (char *buffer) { - path = getcpy ("@"); + path = strdup ("@"); for (;;) { switch (my_lex (buffer)) { @@ -563,7 +553,7 @@ route (char *buffer) break; default: - sprintf (err, "no sub-domain in domain-part of address (%s)", buffer); + snprintf(err, sizeof err, "no sub-domain in domain-part of address (%s)", buffer); return NOTOK; } switch (my_lex (buffer)) { @@ -579,7 +569,7 @@ route (char *buffer) break; default: - sprintf (err, "no at-sign found for next domain in route (%s)", + snprintf(err, sizeof err, "no at-sign found for next domain in route (%s)", buffer); } break; @@ -596,7 +586,7 @@ route (char *buffer) return OK; default: - sprintf (err, "no colon found to terminate route (%s)", buffer); + snprintf(err, sizeof err, "no colon found to terminate route (%s)", buffer); return NOTOK; } } @@ -652,7 +642,7 @@ my_lex (char *buffer) if (--i < 0) { *bp = 0; note = note ? add (buffer, add (" ", note)) - : getcpy (buffer); + : strdup (buffer); return my_lex (buffer); } } @@ -741,22 +731,22 @@ got_atom: ; char * -legal_person (char *p) +legal_person (const char *p) { int i; - register char *cp; + const char *cp; static char buffer[BUFSIZ]; if (*p == '"') - return p; + return (char *) p; for (cp = p; *cp; cp++) for (i = 0; special[i].lx_chr; i++) if (*cp == special[i].lx_chr) { - sprintf (buffer, "\"%s\"", p); + snprintf(buffer, sizeof buffer, "\"%s\"", p); return buffer; } - return p; + return (char *) p; } @@ -764,7 +754,7 @@ int mfgets (FILE *in, char **bp) { int i; - register char *cp, *dp, *ep; + char *cp, *dp, *ep; static int len = 0; static char *pp = NULL;