summaryrefslogtreecommitdiff
path: root/mailutils
diff options
context:
space:
mode:
authorAaro Koskinen2013-02-25 00:45:06 +0200
committerDenys Vlasenko2013-03-18 18:45:13 +0100
commit14285d14a5826eb172e02cf2f6f1ec096add01b0 (patch)
treec40eb0c4810455b84bd9035444e16f89a4486862 /mailutils
parent7c6f2d4207e11ca60964132deb3bd1c4cb583aba (diff)
downloadbusybox-14285d14a5826eb172e02cf2f6f1ec096add01b0.zip
busybox-14285d14a5826eb172e02cf2f6f1ec096add01b0.tar.gz
sendmail: avoid sending mail to wrong addresses
If we get an address we cannot parse properly, we currently just strip the unknown characters and still try to send it. This is considered harmful as the resulting address may still be valid but different from what the user originally intended. Instead, skip sending to an address we cannot fully understand and print the characters what we have scanned so far. Leading and trailing whitespace is allowed and silently stripped. Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'mailutils')
-rw-r--r--mailutils/sendmail.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c
index c426e9d..4f73512 100644
--- a/mailutils/sendmail.c
+++ b/mailutils/sendmail.c
@@ -94,9 +94,22 @@ static char *sane_address(char *str)
{
char *s = str;
char *p = s;
+ int leading_space = 1;
+ int trailing_space = 0;
+
while (*s) {
- if (isalnum(*s) || '_' == *s || '-' == *s || '.' == *s || '@' == *s) {
+ if (isspace(*s)) {
+ trailing_space = !leading_space;
+ } else {
*p++ = *s;
+ if ((!isalnum(*s) && !strchr("_-.@", *s)) ||
+ trailing_space) {
+ *p = '\0';
+ bb_error_msg("Bad address: %s", str);
+ *str = '\0';
+ return str;
+ }
+ leading_space = 0;
}
s++;
}
@@ -106,6 +119,8 @@ static char *sane_address(char *str)
static void rcptto(const char *s)
{
+ if (!*s)
+ return;
// N.B. we don't die if recipient is rejected, for the other recipients may be accepted
if (250 != smtp_checkp("RCPT TO:<%s>", s, -1))
bb_error_msg("Bad recipient: <%s>", s);