summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/util.c
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2012-07-29 17:21:44 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2012-07-29 17:21:44 +0000
commit372f34631b1ff121b61a45ea95897d3caf8e470d (patch)
treec6e4cde8818fe20fd2b8f819c0a4745eb028c165 /usr.sbin/smtpd/util.c
parent04da5a8af0f210ddec600baed1f0ddcb32e36172 (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
Diffstat (limited to 'usr.sbin/smtpd/util.c')
-rw-r--r--usr.sbin/smtpd/util.c20
1 files changed, 16 insertions, 4 deletions
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