net/softnic: add table action profile
[dpdk.git] / examples / ipsec-secgw / parser.c
index 9d0ea46..91282ca 100644 (file)
@@ -1,37 +1,9 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2016 Intel Corporation
  */
 #include <rte_common.h>
 #include <rte_crypto.h>
+#include <rte_string_fns.h>
 
 #include <cmdline_parse_string.h>
 #include <cmdline_parse_num.h>
@@ -236,23 +208,24 @@ 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 + 1),
+                       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;
        }
-
        if (strlen(ip_str) >= INET_ADDRSTRLEN)
                return -EINVAL;
 
@@ -270,14 +243,16 @@ 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 + 1),
+                                       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;
        }
@@ -544,9 +519,7 @@ parse_cfg_file(const char *cfg_filename)
                                goto error_exit;
                        }
 
-                       strncpy(str + strlen(str), oneline,
-                               strlen(oneline));
-
+                       strcpy(str + strlen(str), oneline);
                        continue;
                }
 
@@ -557,8 +530,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) {