diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-07-29 17:21:44 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-07-29 17:21:44 +0000 |
commit | 372f34631b1ff121b61a45ea95897d3caf8e470d (patch) | |
tree | c6e4cde8818fe20fd2b8f819c0a4745eb028c165 | |
parent | 04da5a8af0f210ddec600baed1f0ddcb32e36172 (diff) |
- introduce xlowercase() and allow lowercase() to fail gracefully
- replace all calls to lowercase() with calls to xlowercase()
- in the format string expansion, lowercase() all formats
we will have to reassess all calls to xlowercase() even though it has never
triggered as far as I know, we can probably gracefully fail some of them.
right now we're just keeping former behaviour.
this commit fixes issue reported by Hugo Osvaldo Barrera where a %u format
could lead to a delivery failure (ie: GILLES@openbsd.org should be expanded
to gilles, not GILLES ... only for local deliveries).
ok chl@ on the idea, ok eric@ on the diff
-rw-r--r-- | usr.sbin/smtpd/aliases.c | 12 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka_session.c | 9 | ||||
-rw-r--r-- | usr.sbin/smtpd/makemap.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/util.c | 20 |
5 files changed, 34 insertions, 16 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c index 7995ecaa1a1..09b6605cab6 100644 --- a/usr.sbin/smtpd/aliases.c +++ b/usr.sbin/smtpd/aliases.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aliases.c,v 1.47 2012/04/21 12:45:05 gilles Exp $ */ +/* $OpenBSD: aliases.c,v 1.48 2012/07/29 17:21:43 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -46,7 +46,7 @@ aliases_exist(objid_t mapid, char *username) struct map_alias *map_alias; char buf[MAX_LOCALPART_SIZE]; - lowercase(buf, username, sizeof(buf)); + xlowercase(buf, username, sizeof(buf)); map_alias = map_lookup(mapid, buf, K_ALIAS); if (map_alias == NULL) return 0; @@ -69,7 +69,7 @@ aliases_get(objid_t mapid, struct expandtree *expandtree, char *username) char buf[MAX_LOCALPART_SIZE]; size_t nbaliases; - lowercase(buf, username, sizeof(buf)); + xlowercase(buf, username, sizeof(buf)); map_alias = map_lookup(mapid, buf, K_ALIAS); if (map_alias == NULL) return 0; @@ -99,7 +99,7 @@ aliases_vdomain_exists(objid_t mapid, char *hostname) struct map_virtual *map_virtual; char buf[MAXHOSTNAMELEN]; - lowercase(buf, hostname, sizeof(buf)); + xlowercase(buf, hostname, sizeof(buf)); map_virtual = map_lookup(mapid, buf, K_VIRTUAL); if (map_virtual == NULL) return 0; @@ -122,7 +122,7 @@ aliases_virtual_exist(objid_t mapid, struct mailaddr *maddr) if (! bsnprintf(buf, sizeof(buf), "%s@%s", maddr->user, maddr->domain)) return 0; - lowercase(buf, buf, sizeof(buf)); + xlowercase(buf, buf, sizeof(buf)); map_virtual = map_lookup(mapid, buf, K_VIRTUAL); if (map_virtual == NULL) { @@ -152,7 +152,7 @@ aliases_virtual_get(objid_t mapid, struct expandtree *expandtree, if (! bsnprintf(buf, sizeof(buf), "%s@%s", maddr->user, maddr->domain)) return 0; - lowercase(buf, buf, sizeof(buf)); + xlowercase(buf, buf, sizeof(buf)); map_virtual = map_lookup(mapid, buf, K_VIRTUAL); if (map_virtual == NULL) { diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c index b0b1423ad21..f0eec8e037e 100644 --- a/usr.sbin/smtpd/lka_session.c +++ b/usr.sbin/smtpd/lka_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_session.c,v 1.18 2012/07/29 16:33:01 eric Exp $ */ +/* $OpenBSD: lka_session.c,v 1.19 2012/07/29 17:21:43 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -94,7 +94,7 @@ lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep) user = ep->dest.user; else user = ep->agent.mda.to.user; - lowercase(username, user, sizeof(username)); + xlowercase(username, user, sizeof(username)); /* gilles+hackers@ -> gilles@ */ if ((tag = strchr(username, '+')) != NULL) { @@ -505,6 +505,7 @@ lka_session_expand_format(char *buf, size_t len, struct envelope *ep) struct user_backend *ub; struct mta_user u; char lbuffer[MAX_RULEBUFFER_LEN]; + char tmpbuf[MAX_RULEBUFFER_LEN]; bzero(lbuffer, sizeof (lbuffer)); pbuf = lbuffer; @@ -580,6 +581,10 @@ lka_session_expand_format(char *buf, size_t len, struct envelope *ep) goto copy; } + if (! lowercase(tmpbuf, string, sizeof tmpbuf)) + return 0; + string = tmpbuf; + if (digit == 1) { size_t idx = *(tmp - 1) - '0'; diff --git a/usr.sbin/smtpd/makemap.c b/usr.sbin/smtpd/makemap.c index 6b0797839cc..36126b25a68 100644 --- a/usr.sbin/smtpd/makemap.c +++ b/usr.sbin/smtpd/makemap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: makemap.c,v 1.32 2011/05/16 21:27:38 jasper Exp $ */ +/* $OpenBSD: makemap.c,v 1.33 2012/07/29 17:21:43 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -276,7 +276,7 @@ parse_mapentry(char *line, size_t len, size_t lineno) goto bad; } else if (type == T_ALIASES) { - lowercase(key.data, key.data, strlen(key.data) + 1); + xlowercase(key.data, key.data, strlen(key.data) + 1); if (! make_aliases(&val, valp)) goto bad; } diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index ac91a836c58..b2b72a90f4c 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.312 2012/07/29 16:33:01 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.313 2012/07/29 17:21:43 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -1183,7 +1183,8 @@ int valid_domainpart(const char *); char *ss_to_text(struct sockaddr_storage *); char *time_to_text(time_t); int secure_file(int, char *, char *, uid_t, int); -void lowercase(char *, char *, size_t); +int lowercase(char *, char *, size_t); +void xlowercase(char *, char *, size_t); void sa_set_port(struct sockaddr *, int); u_int64_t generate_uid(void); void fdlimit(double); diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index 96e8350264e..53b0dd8d884 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.66 2012/07/12 08:51:43 chl Exp $ */ +/* $OpenBSD: util.c,v 1.67 2012/07/29 17:21:43 gilles Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -711,19 +711,31 @@ addargs(arglist *args, char *fmt, ...) args->list[args->num] = NULL; } -void +int lowercase(char *buf, char *s, size_t len) { if (len == 0) - fatalx("lowercase: len == 0"); + return 0; if (strlcpy(buf, s, len) >= len) - fatalx("lowercase: truncation"); + return 0; while (*buf != '\0') { *buf = tolower((int)*buf); buf++; } + + return 1; +} + +void +xlowercase(char *buf, char *s, size_t len) +{ + if (len == 0) + fatalx("lowercase: len == 0"); + + if (! lowercase(buf, s, len)) + fatalx("lowercase: truncation"); } void |