The invalid input 72817 (2^16*10/9) is parsed as a valid value.
7281 * 10 + 7 = 72817 == 7281 (mod 2^16), so the prev check fails.
Signed-off-by: Phil Carmody <phil@dovecot.fi>
static int uri_parse_port(struct uri_parser *parser, struct uri_authority *auth)
{
- in_port_t port = 0;
+ unsigned long port = 0;
int count = 0;
/* RFC 3986:
*/
while (parser->cur < parser->end && i_isdigit(*parser->cur)) {
- in_port_t prev = port;
-
- port = port * 10 + (in_port_t)(parser->cur[0] - '0');
- if (port < prev) {
+ port = port * 10 + (parser->cur[0] - '0');
+ if (port > (in_port_t)-1) {
parser->error = "Port number is too high";
return -1;
}