Discussion:
[bug-mailutils] SMTP_PORT should pass to htons()
Robert Young
2017-10-20 01:39:29 UTC
Permalink
ERROR: connect to wrong port when smtp_port specified

tmp # date | /usr/bin/mail --debug-level=mailer.prot --exec='set
sendmail=smtps://your_mail:***@smtp.gmail.com:465'
--append='From: Test <***@gmail.com>' --subject=Test
***@gmail.com
mail: Cannot open mailer: Connection timed out
mail: cannot send message: Connection timed out
tmp #
tmp # netstat -natp | grep /mail
tcp 0 1 192.168.1.113:12863 74.125.204.109:53505
SYN_SENT 31829/mail
tmp #


PATCH to solve this issue:

--- mailutils-3.3/libmailutils/sockaddr/fromnode.c 2017-06-08
13:08:20.000000000 +0000
+++ mailutils-3.3/libmailutils/sockaddr/fromnode.c 2017-10-20
00:57:02.928152699 +0000
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <limits.h>
#include <mailutils/sockaddr.h>
#include <mailutils/url.h>
#include <mailutils/io.h>
@@ -194,8 +195,10 @@
return MU_ERR_SERVICE;
port = sp->s_port;
}
- else if (n == 0 || (port = n) != n)
- return MU_ERR_PARSE; /* FIXME: need MU_ERR_RANGE? */
+ else if (n == 0 || n > USHRT_MAX)
+ return ERANGE;
+ else
+ port = htons (n);
}
else if (mh->port)
port = htons (mh->port);


PATCHED_TESTS:

TEST1 PORT==0 :
tmp # date | /usr/bin/mail --debug-level=mailer.prot --exec='set
sendmail=smtps://your_mail:***@smtp.gmail.com:0'
--append='From: Test <***@gmail.com>' --subject=Test
***@gmail.com
mail: Cannot open mailer: Numerical result out of range
mail: cannot send message: Numerical result out of range

TEST2 PORT==65536 :
tmp # date | /usr/bin/mail --debug-level=mailer.prot --exec='set
sendmail=smtps://your_mail:***@smtp.gmail.com:655
36' --append='From: Test <***@gmail.com>' --subject=Test
***@gmail.com
mail: Cannot create mailer: Numerical result out of range
mail: cannot send message: Numerical result out of range

TEST3 PORT=="bad" :
tmp # date | /usr/bin/mail --debug-level=mailer.prot --exec='set
sendmail=smtps://your_mail:***@smtp.gmail.com:bad
' --append='From: Test <***@gmail.com>' --subject=Test
***@gmail.com
mail: Cannot create mailer: Invalid port or service specification
mail: cannot send message: Invalid port or service specification

TEST4 PORT=="smtps" :
tmp # date | /usr/bin/mail --debug-level=mailer.prot --exec='set
sendmail=smtps://your_mail:***@smtp.gmail.com:smt
ps' --append='From: Test <***@gmail.com>' --subject=Test
***@gmail.com
mail: S: 220 smtp.gmail.com ESMTP t9sm27356803pgr.3 - gsmtp
...
mail: S: 250 2.0.0 OK 1508461891 t9sm27356803pgr.3 - gsmtp
mail: C: QUIT
mail: S: 221 2.0.0 closing connection t9sm27356803pgr.3 - gsmtp

TEST5 PORT==465 :
tmp # date | /usr/bin/mail --debug-level=mailer.prot --exec='set
sendmail=smtps://your_mail:***@smtp.gmail.com:465
' --append='From: Test <***@gmail.com>' --subject=Test
***@gmail.com
mail: S: 220 smtp.gmail.com ESMTP g24sm29902885pfk.0 - gsmtp
mail: C: QUIT
mail: S: 250 2.0.0 OK 1508461944 g24sm29902885pfk.0 - gsmtp
mail: S: 221 2.0.0 closing connection g24sm29902885pfk.0 - gsmtp
Sergey Poznyakoff
2017-11-01 06:55:51 UTC
Permalink
Hi Robert,
Post by Robert Young
ERROR: connect to wrong port when smtp_port specified
*and* mailutils was compiled with --disable-ipv6

Thanks for the patch. I pushed it.

Regards,
Sergey

Loading...