From: Reshma Pattan Date: Wed, 9 May 2018 16:11:06 +0000 (+0100) Subject: examples/ipsec-secgw: replace strncpy with strlcpy X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=ae943ebe1ed3;p=dpdk.git examples/ipsec-secgw: replace strncpy with strlcpy Use strlcpy instead of strncpy. Use strcpy where boundchecks on destination is not needed. Fixes: 0d547ed037 ("examples/ipsec-secgw: support configuration file") Fixes: 07b156199f ("examples/ipsec-secgw: fix configuration string termination") Fixes: a1469c319f ("examples/ipsec-secgw: fix configuration parsing") Cc: stable@dpdk.org Signed-off-by: Reshma Pattan Acked-by: Pablo de Lara --- diff --git a/examples/ipsec-secgw/parser.c b/examples/ipsec-secgw/parser.c index 2403b564db..e2e3429085 100644 --- a/examples/ipsec-secgw/parser.c +++ b/examples/ipsec-secgw/parser.c @@ -3,6 +3,7 @@ */ #include #include +#include #include #include @@ -207,19 +208,20 @@ inet_pton6(const char *src, unsigned char *dst) int parse_ipv4_addr(const char *token, struct in_addr *ipv4, uint32_t *mask) { - char ip_str[256] = {0}; + char ip_str[INET_ADDRSTRLEN] = {0}; char *pch; pch = strchr(token, '/'); if (pch != NULL) { - strncpy(ip_str, token, pch - token); + strlcpy(ip_str, token, RTE_MIN((unsigned int long)(pch - token), + sizeof(ip_str))); pch += 1; if (is_str_num(pch) != 0) return -EINVAL; if (mask) *mask = atoi(pch); } else { - strncpy(ip_str, token, sizeof(ip_str) - 1); + strlcpy(ip_str, token, sizeof(ip_str)); if (mask) *mask = 0; } @@ -241,14 +243,15 @@ parse_ipv6_addr(const char *token, struct in6_addr *ipv6, uint32_t *mask) pch = strchr(token, '/'); if (pch != NULL) { - strncpy(ip_str, token, pch - token); + strlcpy(ip_str, token, RTE_MIN((unsigned int long)(pch - token), + sizeof(ip_str))); pch += 1; if (is_str_num(pch) != 0) return -EINVAL; if (mask) *mask = atoi(pch); } else { - strncpy(ip_str, token, sizeof(ip_str) - 1); + strlcpy(ip_str, token, sizeof(ip_str)); if (mask) *mask = 0; } @@ -515,9 +518,7 @@ parse_cfg_file(const char *cfg_filename) goto error_exit; } - strncpy(str + strlen(str), oneline, - strlen(oneline)); - + strcpy(str + strlen(str), oneline); continue; } @@ -528,8 +529,7 @@ parse_cfg_file(const char *cfg_filename) cfg_filename, line_num); goto error_exit; } - strncpy(str + strlen(str), oneline, - strlen(oneline)); + strcpy(str + strlen(str), oneline); str[strlen(str)] = '\n'; if (cmdline_parse(cl, str) < 0) {