]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-parser - Use net_addr2ip() to parse IPv6 addresses
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 12 Apr 2022 09:01:49 +0000 (12:01 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 14 Apr 2022 11:10:37 +0000 (11:10 +0000)
src/lib-smtp/smtp-parser.c

index 5672ff0c4813963e82446717e2f73cf9a5862ff2..2a6255790a9de5bf8e675b5f2c1ad5d1f601d0c6 100644 (file)
@@ -292,7 +292,6 @@ int smtp_parser_parse_address_literal(struct smtp_parser *parser,
 {
        const unsigned char *pblock;
        struct in_addr ip4;
-       struct in6_addr ip6;
        bool ipv6 = FALSE;
        string_t *value = NULL, *tagbuf;
        int ret;
@@ -379,16 +378,14 @@ int smtp_parser_parse_address_literal(struct smtp_parser *parser,
                        str_append_data(value, pblock, parser->cur - pblock);
 
                if (ipv6) {
-                       i_zero(&ip6);
-                       if (inet_pton(AF_INET6, t_strndup(pblock,
-                               parser->cur - pblock), &ip6) <= 0) {
+                       struct ip_addr ip;
+                       if (net_addr2ip(t_strndup(pblock, parser->cur - pblock),
+                                       &ip) < 0) {
                                parser->error = "Invalid IPv6 address literal";
                                return -1;
                        }
-                       if (ip_r != NULL) {
-                               ip_r->family = AF_INET6;
-                               ip_r->u.ip6 = ip6;
-                       }
+                       if (ip_r != NULL)
+                               *ip_r = ip;
                }
        }