examples/ipsec-secgw: fix IP address parsing
authorKirill Rybalchenko <kirill.rybalchenko@intel.com>
Mon, 14 May 2018 10:00:51 +0000 (11:00 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 14 May 2018 11:57:08 +0000 (13:57 +0200)
In strlcpy function parameters there was no allowance for
null terminator, so ip address was copied without last character.

Fixes: ae943ebe1ed3 ("examples/ipsec-secgw: replace strncpy with strlcpy")
Cc: stable@dpdk.org
Signed-off-by: Kirill Rybalchenko <kirill.rybalchenko@intel.com>
Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
examples/ipsec-secgw/parser.c

index e2e3429..91282ca 100644 (file)
@@ -213,8 +213,9 @@ parse_ipv4_addr(const char *token, struct in_addr *ipv4, uint32_t *mask)
 
        pch = strchr(token, '/');
        if (pch != NULL) {
-               strlcpy(ip_str, token, RTE_MIN((unsigned int long)(pch - token),
-                                       sizeof(ip_str)));
+               strlcpy(ip_str, token,
+                       RTE_MIN((unsigned int long)(pch - token + 1),
+                       sizeof(ip_str)));
                pch += 1;
                if (is_str_num(pch) != 0)
                        return -EINVAL;
@@ -225,7 +226,6 @@ parse_ipv4_addr(const char *token, struct in_addr *ipv4, uint32_t *mask)
                if (mask)
                        *mask = 0;
        }
-
        if (strlen(ip_str) >= INET_ADDRSTRLEN)
                return -EINVAL;
 
@@ -243,7 +243,8 @@ parse_ipv6_addr(const char *token, struct in6_addr *ipv6, uint32_t *mask)
 
        pch = strchr(token, '/');
        if (pch != NULL) {
-               strlcpy(ip_str, token, RTE_MIN((unsigned int long)(pch - token),
+               strlcpy(ip_str, token,
+                       RTE_MIN((unsigned int long)(pch - token + 1),
                                        sizeof(ip_str)));
                pch += 1;
                if (is_str_num(pch) != 0)