sendmail: avoid sending mail to wrong addresses
authorAaro Koskinen <aaro.koskinen@iki.fi>
Sun, 24 Feb 2013 22:45:06 +0000 (00:45 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 18 Mar 2013 17:45:13 +0000 (18:45 +0100)
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>
mailutils/sendmail.c

index c426e9d851f00f39533e7b869732075e438a7599..4f73512e99402f0014a8a679ad9fd5730e94b273 100644 (file)
@@ -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);