get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/35308/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 35308,
    "url": "http://patches.dpdk.org/api/patches/35308/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20180220170727.220340-1-bruce.richardson@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20180220170727.220340-1-bruce.richardson@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20180220170727.220340-1-bruce.richardson@intel.com",
    "date": "2018-02-20T17:07:27",
    "name": "[dpdk-dev,RFC] use strlcpy for string copies",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "2229e13303dba443126d1ef90dd190fba498a49d",
    "submitter": {
        "id": 20,
        "url": "http://patches.dpdk.org/api/people/20/?format=api",
        "name": "Bruce Richardson",
        "email": "bruce.richardson@intel.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20180220170727.220340-1-bruce.richardson@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/35308/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/35308/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id A53A42BE5;\n\tTue, 20 Feb 2018 18:07:40 +0100 (CET)",
            "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n\tby dpdk.org (Postfix) with ESMTP id B14EB374\n\tfor <dev@dpdk.org>; Tue, 20 Feb 2018 18:07:38 +0100 (CET)",
            "from fmsmga003.fm.intel.com ([10.253.24.29])\n\tby fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t20 Feb 2018 09:07:37 -0800",
            "from silpixa00399126.ir.intel.com (HELO\n\tsilpixa00399126.ger.corp.intel.com) ([10.237.223.223])\n\tby FMSMGA003.fm.intel.com with ESMTP; 20 Feb 2018 09:07:36 -0800"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.46,540,1511856000\"; d=\"scan'208\";a=\"28535646\"",
        "From": "Bruce Richardson <bruce.richardson@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "Bruce Richardson <bruce.richardson@intel.com>",
        "Date": "Tue, 20 Feb 2018 17:07:27 +0000",
        "Message-Id": "<20180220170727.220340-1-bruce.richardson@intel.com>",
        "X-Mailer": "git-send-email 2.14.3",
        "Subject": "[dpdk-dev] [RFC PATCH] use strlcpy for string copies",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Following on from the number of patches needing to be done for strncpy\nissues highlighted by coverity...\n\nThe strncpy function is error prone for doing \"safe\" string copies, so\nwe generally try to use \"snprintf\" instead in the code. The function\n\"strlcpy\" is a better alternative, though, since it better conveys the\nintention of the programmer, and doesn't suffer from the non-null\nterminating behaviour of it's n'ed brethern.\n\nThe downside of this function is that it is not available by default\non linux, though standard in the BSD's. It is available on most\ndistros by installing \"libbsd\" package.\n\nThis RFC therefore provides the following in rte_string_fns.h to ensure\nthat strlcpy is available there:\n* for BSD, include string.h as normal\n* if RTE_USE_LIBBSD is set, include <bsd/string.h>\n* if not set, fallback to snprintf for strlcpy\n\nUsing make build system, the RTE_USE_LIBBSD is a hard-coded value to \"n\",\nbut when using meson, it's automatically set based on what is available\non the platform.\n\nInstances of snprintf using \"%s\" alone as a string format are replaced\nvia coccinelle script with the new strlcpy function. Instances of\nstrncpy should be replaced too, but requires manual checking as to\nwhether the NULL termination is manually done afterward or not.\n\nSigned-off-by: Bruce Richardson <bruce.richardson@intel.com>\n---\n app/pdump/main.c                                           | 11 +++++------\n app/test-pmd/parameters.c                                  |  5 ++---\n config/common_base                                         |  1 +\n config/meson.build                                         |  7 +++++++\n devtools/cocci/strlcpy.cocci                               |  8 ++++++++\n drivers/net/bonding/rte_eth_bond_pmd.c                     |  2 +-\n drivers/net/failsafe/failsafe_args.c                       |  5 +++--\n drivers/net/mlx4/mlx4_ethdev.c                             |  2 +-\n drivers/net/mlx5/mlx5_ethdev.c                             |  2 +-\n drivers/net/mrvl/mrvl_qos.c                                |  2 +-\n drivers/net/tap/rte_eth_tap.c                              |  5 +++--\n .../ip_pipeline/pipeline/pipeline_flow_classification_be.c |  4 ++--\n examples/ip_pipeline/pipeline/pipeline_passthrough_be.c    |  4 ++--\n examples/load_balancer/config.c                            |  2 +-\n lib/librte_cmdline/cmdline_parse.c                         |  6 +++---\n lib/librte_cmdline/cmdline_parse_etheraddr.c               |  2 +-\n lib/librte_cmdline/cmdline_parse_ipaddr.c                  |  2 +-\n lib/librte_cmdline/cmdline_parse_portlist.c                |  2 +-\n lib/librte_cmdline/cmdline_parse_string.c                  |  4 ++--\n lib/librte_eal/common/eal_common_bus.c                     |  3 ++-\n lib/librte_eal/common/include/rte_string_fns.h             | 14 ++++++++++++++\n lib/librte_pdump/rte_pdump.c                               |  9 +++++----\n test/test/test_cmdline_cirbuf.c                            |  2 +-\n test/test/test_eal_flags.c                                 | 10 ++++++----\n test/test/test_malloc.c                                    |  2 +-\n 25 files changed, 75 insertions(+), 41 deletions(-)\n create mode 100644 devtools/cocci/strlcpy.cocci",
    "diff": "diff --git a/app/pdump/main.c b/app/pdump/main.c\nindex f6865bdbd..d29de0321 100644\n--- a/app/pdump/main.c\n+++ b/app/pdump/main.c\n@@ -24,6 +24,7 @@\n #include <rte_kvargs.h>\n #include <rte_mempool.h>\n #include <rte_ring.h>\n+#include <rte_string_fns.h>\n #include <rte_pdump.h>\n \n #define CMD_LINE_OPT_PDUMP \"pdump\"\n@@ -408,17 +409,15 @@ launch_args_parse(int argc, char **argv, char *prgname)\n \t\t\tif (!strncmp(long_option[option_index].name,\n \t\t\t\t\tCMD_LINE_OPT_SER_SOCK_PATH,\n \t\t\t\t\tsizeof(CMD_LINE_OPT_SER_SOCK_PATH))) {\n-\t\t\t\tsnprintf(server_socket_path,\n-\t\t\t\t\tsizeof(server_socket_path), \"%s\",\n-\t\t\t\t\toptarg);\n+\t\t\t\tstrlcpy(server_socket_path, optarg,\n+\t\t\t\t\tsizeof(server_socket_path));\n \t\t\t}\n \n \t\t\tif (!strncmp(long_option[option_index].name,\n \t\t\t\t\tCMD_LINE_OPT_CLI_SOCK_PATH,\n \t\t\t\t\tsizeof(CMD_LINE_OPT_CLI_SOCK_PATH))) {\n-\t\t\t\tsnprintf(client_socket_path,\n-\t\t\t\t\tsizeof(client_socket_path), \"%s\",\n-\t\t\t\t\toptarg);\n+\t\t\t\tstrlcpy(client_socket_path, optarg,\n+\t\t\t\t\tsizeof(client_socket_path));\n \t\t\t}\n \n \t\t\tbreak;\ndiff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c\nindex 97d22b860..2192bdcdf 100644\n--- a/app/test-pmd/parameters.c\n+++ b/app/test-pmd/parameters.c\n@@ -658,9 +658,8 @@ launch_args_parse(int argc, char** argv)\n \t\t\tif (!strcmp(lgopts[opt_idx].name, \"cmdline-file\")) {\n \t\t\t\tprintf(\"CLI commands to be read from %s\\n\",\n \t\t\t\t       optarg);\n-\t\t\t\tsnprintf(cmdline_filename,\n-\t\t\t\t\t sizeof(cmdline_filename), \"%s\",\n-\t\t\t\t\t optarg);\n+\t\t\t\tstrlcpy(cmdline_filename, optarg,\n+\t\t\t\t\tsizeof(cmdline_filename));\n \t\t\t}\n \t\t\tif (!strcmp(lgopts[opt_idx].name, \"auto-start\")) {\n \t\t\t\tprintf(\"Auto-start selected\\n\");\ndiff --git a/config/common_base b/config/common_base\nindex ad03cf433..20d4cbcf2 100644\n--- a/config/common_base\n+++ b/config/common_base\n@@ -76,6 +76,7 @@ CONFIG_RTE_EAL_VFIO=n\n CONFIG_RTE_MAX_VFIO_GROUPS=64\n CONFIG_RTE_MALLOC_DEBUG=n\n CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n\n+CONFIG_RTE_USE_LIBBSD=n\n \n #\n # Recognize/ignore the AVX/AVX512 CPU flags for performance/power testing.\ndiff --git a/config/meson.build b/config/meson.build\nindex f8c67578d..77af5d897 100644\n--- a/config/meson.build\n+++ b/config/meson.build\n@@ -38,6 +38,13 @@ if numa_dep.found() and cc.has_header('numaif.h')\n \tdpdk_extra_ldflags += '-lnuma'\n endif\n \n+# check for strlcpy\n+if host_machine.system() == 'linux' and cc.find_library('bsd', required: false).found()\n+\tdpdk_conf.set('RTE_USE_LIBBSD', 1)\n+\tadd_project_link_arguments('-lbsd', language: 'c')\n+\tdpdk_extra_ldflags += '-lbsd'\n+endif\n+\n # add -include rte_config to cflags\n add_project_arguments('-include', 'rte_config.h', language: 'c')\n \ndiff --git a/devtools/cocci/strlcpy.cocci b/devtools/cocci/strlcpy.cocci\nnew file mode 100644\nindex 000000000..335e27128\n--- /dev/null\n+++ b/devtools/cocci/strlcpy.cocci\n@@ -0,0 +1,8 @@\n+@use_strlcpy@\n+identifier src, dst;\n+expression size;\n+@@\n+(\n+- snprintf(dst, size, \"%s\", src)\n++ strlcpy(dst, src, size)\n+)\ndiff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c\nindex c34c3251f..f958ece72 100644\n--- a/drivers/net/bonding/rte_eth_bond_pmd.c\n+++ b/drivers/net/bonding/rte_eth_bond_pmd.c\n@@ -617,7 +617,7 @@ mode6_debug(const char __attribute__((unused)) *info, struct ether_hdr *eth_h,\n \tuint16_t offset = get_vlan_offset(eth_h, &ether_type);\n \n #ifdef RTE_LIBRTE_BOND_DEBUG_ALB\n-\tsnprintf(buf, 16, \"%s\", info);\n+\tstrlcpy(buf, info, 16);\n #endif\n \n \tif (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {\ndiff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c\nindex 366dbea16..ea934f92a 100644\n--- a/drivers/net/failsafe/failsafe_args.c\n+++ b/drivers/net/failsafe/failsafe_args.c\n@@ -14,6 +14,7 @@\n #include <rte_devargs.h>\n #include <rte_malloc.h>\n #include <rte_kvargs.h>\n+#include <rte_string_fns.h>\n \n #include \"failsafe_private.h\"\n \n@@ -340,7 +341,7 @@ fs_remove_sub_devices_definition(char params[DEVARGS_MAXLEN])\n \t\ta = b + 1;\n \t}\n out:\n-\tsnprintf(params, DEVARGS_MAXLEN, \"%s\", buffer);\n+\tstrlcpy(params, buffer, DEVARGS_MAXLEN);\n \treturn 0;\n }\n \n@@ -392,7 +393,7 @@ failsafe_args_parse(struct rte_eth_dev *dev, const char *params)\n \tret = 0;\n \tpriv->subs_tx = FAILSAFE_MAX_ETHPORTS;\n \t/* default parameters */\n-\tn = snprintf(mut_params, sizeof(mut_params), \"%s\", params);\n+\tn = strlcpy(mut_params, params, sizeof(mut_params));\n \tif (n >= sizeof(mut_params)) {\n \t\tERROR(\"Parameter string too long (>=%zu)\",\n \t\t\t\tsizeof(mut_params));\ndiff --git a/drivers/net/mlx4/mlx4_ethdev.c b/drivers/net/mlx4/mlx4_ethdev.c\nindex 3bc692731..c92dd6d43 100644\n--- a/drivers/net/mlx4/mlx4_ethdev.c\n+++ b/drivers/net/mlx4/mlx4_ethdev.c\n@@ -120,7 +120,7 @@ mlx4_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE])\n \t\t\tgoto try_dev_id;\n \t\tdev_port_prev = dev_port;\n \t\tif (dev_port == (priv->port - 1u))\n-\t\t\tsnprintf(match, sizeof(match), \"%s\", name);\n+\t\t\tstrlcpy(match, name, sizeof(match));\n \t}\n \tclosedir(dir);\n \tif (match[0] == '\\0') {\ndiff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c\nindex 666507691..894a045ec 100644\n--- a/drivers/net/mlx5/mlx5_ethdev.c\n+++ b/drivers/net/mlx5/mlx5_ethdev.c\n@@ -163,7 +163,7 @@ priv_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE])\n \t\t\tgoto try_dev_id;\n \t\tdev_port_prev = dev_port;\n \t\tif (dev_port == (priv->port - 1u))\n-\t\t\tsnprintf(match, sizeof(match), \"%s\", name);\n+\t\t\tstrlcpy(match, name, sizeof(match));\n \t}\n \tclosedir(dir);\n \tif (match[0] == '\\0')\ndiff --git a/drivers/net/mrvl/mrvl_qos.c b/drivers/net/mrvl/mrvl_qos.c\nindex fbb368131..edc4d92d6 100644\n--- a/drivers/net/mrvl/mrvl_qos.c\n+++ b/drivers/net/mrvl/mrvl_qos.c\n@@ -190,7 +190,7 @@ get_entry_values(const char *entry, uint8_t *tab,\n \t\treturn -1;\n \n \t/* Copy the entry to safely use rte_strsplit(). */\n-\tsnprintf(entry_cpy, RTE_DIM(entry_cpy), \"%s\", entry);\n+\tstrlcpy(entry_cpy, entry, RTE_DIM(entry_cpy));\n \n \t/*\n \t * If there are more tokens than array size, rte_strsplit will\ndiff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c\nindex f09db0ea9..fbba9aa63 100644\n--- a/drivers/net/tap/rte_eth_tap.c\n+++ b/drivers/net/tap/rte_eth_tap.c\n@@ -15,6 +15,7 @@\n #include <rte_net.h>\n #include <rte_debug.h>\n #include <rte_ip.h>\n+#include <rte_string_fns.h>\n \n #include <sys/types.h>\n #include <sys/stat.h>\n@@ -1548,7 +1549,7 @@ set_interface_name(const char *key __rte_unused,\n \tchar *name = (char *)extra_args;\n \n \tif (value)\n-\t\tsnprintf(name, RTE_ETH_NAME_MAX_LEN - 1, \"%s\", value);\n+\t\tstrlcpy(name, value, RTE_ETH_NAME_MAX_LEN - 1);\n \telse\n \t\tsnprintf(name, RTE_ETH_NAME_MAX_LEN - 1, \"%s%d\",\n \t\t\t DEFAULT_TAP_NAME, (tap_unit - 1));\n@@ -1564,7 +1565,7 @@ set_remote_iface(const char *key __rte_unused,\n \tchar *name = (char *)extra_args;\n \n \tif (value)\n-\t\tsnprintf(name, RTE_ETH_NAME_MAX_LEN, \"%s\", value);\n+\t\tstrlcpy(name, value, RTE_ETH_NAME_MAX_LEN);\n \n \treturn 0;\n }\ndiff --git a/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c b/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c\nindex 097ec3469..3e26ae86b 100644\n--- a/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c\n+++ b/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c\n@@ -8,6 +8,7 @@\n #include <rte_malloc.h>\n #include <rte_table_hash.h>\n #include <rte_byteorder.h>\n+#include <rte_string_fns.h>\n #include <pipeline.h>\n \n #include \"pipeline_flow_classification_be.h\"\n@@ -280,8 +281,7 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,\n \t\t\t\t\"\\\"%s\\\" is too long\", params->name,\n \t\t\t\targ_name);\n \n-\t\t\tsnprintf(key_mask_str, mask_str_len + 1, \"%s\",\n-\t\t\t\targ_value);\n+\t\t\tstrlcpy(key_mask_str, arg_value, mask_str_len + 1);\n \n \t\t\tcontinue;\n \t\t}\ndiff --git a/examples/ip_pipeline/pipeline/pipeline_passthrough_be.c b/examples/ip_pipeline/pipeline/pipeline_passthrough_be.c\nindex b2bbaedda..1c44e75df 100644\n--- a/examples/ip_pipeline/pipeline/pipeline_passthrough_be.c\n+++ b/examples/ip_pipeline/pipeline/pipeline_passthrough_be.c\n@@ -8,6 +8,7 @@\n #include <rte_common.h>\n #include <rte_malloc.h>\n #include <rte_byteorder.h>\n+#include <rte_string_fns.h>\n #include <rte_table_stub.h>\n #include <rte_table_hash.h>\n #include <rte_pipeline.h>\n@@ -524,8 +525,7 @@ pipeline_passthrough_parse_args(struct pipeline_passthrough_params *p,\n \t\t\t\t\"\\\"%s\\\" too long\", params->name,\n \t\t\t\targ_name);\n \n-\t\t\tsnprintf(dma_mask_str, mask_str_len + 1,\n-\t\t\t\t\"%s\", arg_value);\n+\t\t\tstrlcpy(dma_mask_str, arg_value, mask_str_len + 1);\n \n \t\t\tp->dma_enabled = 1;\n \ndiff --git a/examples/load_balancer/config.c b/examples/load_balancer/config.c\nindex b5b66368d..972c85c5b 100644\n--- a/examples/load_balancer/config.c\n+++ b/examples/load_balancer/config.c\n@@ -121,7 +121,7 @@ str_to_unsigned_array(\n \tint i, num_splits = 0;\n \n \t/* copy s so we don't modify original string */\n-\tsnprintf(str, sizeof(str), \"%s\", s);\n+\tstrlcpy(str, s, sizeof(str));\n \tnum_splits = rte_strsplit(str, sizeof(str), splits, num_vals, separator);\n \n \terrno = 0;\ndiff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c\nindex e88e4e110..961f9befd 100644\n--- a/lib/librte_cmdline/cmdline_parse.c\n+++ b/lib/librte_cmdline/cmdline_parse.c\n@@ -251,7 +251,7 @@ cmdline_parse(struct cmdline *cl, const char * buf)\n \t}\n \n #ifdef RTE_LIBRTE_CMDLINE_DEBUG\n-\tsnprintf(debug_buf, (linelen>64 ? 64 : linelen), \"%s\", buf);\n+\tstrlcpy(debug_buf, buf, (linelen > 64 ? 64 : linelen));\n \tdebug_printf(\"Parse line : len=%d, <%s>\\n\", linelen, debug_buf);\n #endif\n \n@@ -436,7 +436,7 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state,\n \t\t\t\tif ((unsigned)(comp_len + 1) > size)\n \t\t\t\t\treturn 0;\n \n-\t\t\t\tsnprintf(dst, size, \"%s\", comp_buf);\n+\t\t\t\tstrlcpy(dst, comp_buf, size);\n \t\t\t\tdst[comp_len] = 0;\n \t\t\t\treturn 2;\n \t\t\t}\n@@ -513,7 +513,7 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state,\n \t\t\t\t\tcontinue;\n \t\t\t\t}\n \t\t\t\t(*state)++;\n-\t\t\t\tl=snprintf(dst, size, \"%s\", tmpbuf);\n+\t\t\t\tl=strlcpy(dst, tmpbuf, size);\n \t\t\t\tif (l>=0 && token_hdr.ops->get_help) {\n \t\t\t\t\ttoken_hdr.ops->get_help(token_p, tmpbuf,\n \t\t\t\t\t\t\t\tsizeof(tmpbuf));\ndiff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c\nindex 8d2811926..24e04755c 100644\n--- a/lib/librte_cmdline/cmdline_parse_etheraddr.c\n+++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c\n@@ -102,7 +102,7 @@ cmdline_parse_etheraddr(__attribute__((unused)) cmdline_parse_token_hdr_t *tk,\n \t\t\t(token_len != ETHER_ADDRSTRLENSHORT - 1))\n \t\treturn -1;\n \n-\tsnprintf(ether_str, token_len+1, \"%s\", buf);\n+\tstrlcpy(ether_str, buf, token_len + 1);\n \n \ttmp = my_ether_aton(ether_str);\n \tif (tmp == NULL)\ndiff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.c b/lib/librte_cmdline/cmdline_parse_ipaddr.c\nindex ae6ea1007..d34436abc 100644\n--- a/lib/librte_cmdline/cmdline_parse_ipaddr.c\n+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.c\n@@ -277,7 +277,7 @@ cmdline_parse_ipaddr(cmdline_parse_token_hdr_t *tk, const char *buf, void *res,\n \tif (token_len >= INET6_ADDRSTRLEN+4)\n \t\treturn -1;\n \n-\tsnprintf(ip_str, token_len+1, \"%s\", buf);\n+\tstrlcpy(ip_str, buf, token_len + 1);\n \n \t/* convert the network prefix */\n \tif (tk2->ipaddr_data.flags & CMDLINE_IPADDR_NETWORK) {\ndiff --git a/lib/librte_cmdline/cmdline_parse_portlist.c b/lib/librte_cmdline/cmdline_parse_portlist.c\nindex 5952f3438..ad43b522e 100644\n--- a/lib/librte_cmdline/cmdline_parse_portlist.c\n+++ b/lib/librte_cmdline/cmdline_parse_portlist.c\n@@ -94,7 +94,7 @@ cmdline_parse_portlist(__attribute__((unused)) cmdline_parse_token_hdr_t *tk,\n \tif (token_len >= PORTLIST_TOKEN_SIZE)\n \t\treturn -1;\n \n-\tsnprintf(portlist_str, token_len+1, \"%s\", buf);\n+\tstrlcpy(portlist_str, buf, token_len + 1);\n \n \tif (pl) {\n \t\tpl->map = 0;\ndiff --git a/lib/librte_cmdline/cmdline_parse_string.c b/lib/librte_cmdline/cmdline_parse_string.c\nindex abde0412a..9cf41d0f7 100644\n--- a/lib/librte_cmdline/cmdline_parse_string.c\n+++ b/lib/librte_cmdline/cmdline_parse_string.c\n@@ -125,10 +125,10 @@ cmdline_parse_string(cmdline_parse_token_hdr_t *tk, const char *buf, void *res,\n \tif (res) {\n \t\tif ((sd->str != NULL) && (strcmp(sd->str, TOKEN_STRING_MULTI) == 0))\n \t\t\t/* we are sure that token_len is < STR_MULTI_TOKEN_SIZE-1 */\n-\t\t\tsnprintf(res, STR_MULTI_TOKEN_SIZE, \"%s\", buf);\n+\t\t\tstrlcpy(res, buf, STR_MULTI_TOKEN_SIZE);\n \t\telse\n \t\t\t/* we are sure that token_len is < STR_TOKEN_SIZE-1 */\n-\t\t\tsnprintf(res, STR_TOKEN_SIZE, \"%s\", buf);\n+\t\t\tstrlcpy(res, buf, STR_TOKEN_SIZE);\n \n \t\t*((char *)res + token_len) = 0;\n \t}\ndiff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c\nindex 3e022d510..0943851cc 100644\n--- a/lib/librte_eal/common/eal_common_bus.c\n+++ b/lib/librte_eal/common/eal_common_bus.c\n@@ -36,6 +36,7 @@\n \n #include <rte_bus.h>\n #include <rte_debug.h>\n+#include <rte_string_fns.h>\n \n #include \"eal_private.h\"\n \n@@ -212,7 +213,7 @@ rte_bus_find_by_device_name(const char *str)\n \tchar name[RTE_DEV_NAME_MAX_LEN];\n \tchar *c;\n \n-\tsnprintf(name, sizeof(name), \"%s\", str);\n+\tstrlcpy(name, str, sizeof(name));\n \tc = strchr(name, ',');\n \tif (c != NULL)\n \t\tc[0] = '\\0';\ndiff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h\nindex e97047a47..ff4c98b2a 100644\n--- a/lib/librte_eal/common/include/rte_string_fns.h\n+++ b/lib/librte_eal/common/include/rte_string_fns.h\n@@ -45,6 +45,20 @@ int\n rte_strsplit(char *string, int stringlen,\n              char **tokens, int maxtokens, char delim);\n \n+/* pull in a strlcpy function */\n+#ifdef RTE_EXEC_ENV_BSDAPP\n+#include <string.h>\n+\n+#else /* non-BSD platforms */\n+#ifdef RTE_USE_LIBBSD\n+#include <bsd/string.h>\n+\n+#else /* no BSD header files, create own */\n+#define strlcpy(dst, src, size) snprintf(dst, size, \"%s\", src)\n+\n+#endif /* RTE_USE_LIBBSD */\n+#endif /* BSDAPP */\n+\n #ifdef __cplusplus\n }\n #endif\ndiff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c\nindex ec8a5d84c..41a9deeba 100644\n--- a/lib/librte_pdump/rte_pdump.c\n+++ b/lib/librte_pdump/rte_pdump.c\n@@ -17,6 +17,7 @@\n #include <rte_lcore.h>\n #include <rte_log.h>\n #include <rte_errno.h>\n+#include <rte_string_fns.h>\n \n #include \"rte_pdump.h\"\n \n@@ -401,9 +402,9 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)\n \tint ret = 0;\n \n \tif (type == RTE_PDUMP_SOCKET_SERVER && server_socket_dir[0] != 0)\n-\t\tsnprintf(dir, sizeof(dir), \"%s\", server_socket_dir);\n+\t\tstrlcpy(dir, server_socket_dir, sizeof(dir));\n \telse if (type == RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0] != 0)\n-\t\tsnprintf(dir, sizeof(dir), \"%s\", client_socket_dir);\n+\t\tstrlcpy(dir, client_socket_dir, sizeof(dir));\n \telse {\n \t\tif (getuid() != 0) {\n \t\t\tdir_home = getenv(SOCKET_PATH_HOME);\n@@ -891,10 +892,10 @@ rte_pdump_set_socket_dir(const char *path, enum rte_pdump_socktype type)\n \tif (path != NULL) {\n \t\tif (type == RTE_PDUMP_SOCKET_SERVER) {\n \t\t\tcount = sizeof(server_socket_dir);\n-\t\t\tret = snprintf(server_socket_dir, count, \"%s\", path);\n+\t\t\tret = strlcpy(server_socket_dir, path, count);\n \t\t} else {\n \t\t\tcount = sizeof(client_socket_dir);\n-\t\t\tret = snprintf(client_socket_dir, count, \"%s\", path);\n+\t\t\tret = strlcpy(client_socket_dir, path, count);\n \t\t}\n \n \t\tif (ret < 0  || ret >= count) {\ndiff --git a/test/test/test_cmdline_cirbuf.c b/test/test/test_cmdline_cirbuf.c\nindex e9193f66c..8ac326cb0 100644\n--- a/test/test/test_cmdline_cirbuf.c\n+++ b/test/test/test_cmdline_cirbuf.c\n@@ -483,7 +483,7 @@ test_cirbuf_string_get_del_partial(void)\n \tmemset(tmp, 0, sizeof(tmp));\n \tmemset(tmp2, 0, sizeof(tmp));\n \n-\tsnprintf(tmp2, sizeof(tmp2), \"%s\", CIRBUF_STR_HEAD);\n+\tstrlcpy(tmp2, CIRBUF_STR_HEAD, sizeof(tmp2));\n \n \t/*\n \t * initialize circular buffer\ndiff --git a/test/test/test_eal_flags.c b/test/test/test_eal_flags.c\nindex 37c42efe8..93eb7a481 100644\n--- a/test/test/test_eal_flags.c\n+++ b/test/test/test_eal_flags.c\n@@ -1151,11 +1151,12 @@ test_memory_flags(void)\n \t/* add one extra socket */\n \tfor (i = 0; i < num_sockets + 1; i++) {\n \t\tsnprintf(buf, sizeof(buf), \"%s%s\", invalid_socket_mem, DEFAULT_MEM_SIZE);\n-\t\tsnprintf(invalid_socket_mem, sizeof(invalid_socket_mem), \"%s\", buf);\n+\t\tstrlcpy(invalid_socket_mem, buf, sizeof(invalid_socket_mem));\n \n \t\tif (num_sockets + 1 - i > 1) {\n \t\t\tsnprintf(buf, sizeof(buf), \"%s,\", invalid_socket_mem);\n-\t\t\tsnprintf(invalid_socket_mem, sizeof(invalid_socket_mem), \"%s\", buf);\n+\t\t\tstrlcpy(invalid_socket_mem, buf,\n+\t\t\t\tsizeof(invalid_socket_mem));\n \t\t}\n \t}\n \n@@ -1167,11 +1168,12 @@ test_memory_flags(void)\n \t/* add one extra socket */\n \tfor (i = 0; i < num_sockets; i++) {\n \t\tsnprintf(buf, sizeof(buf), \"%s%s\", valid_socket_mem, DEFAULT_MEM_SIZE);\n-\t\tsnprintf(valid_socket_mem, sizeof(valid_socket_mem), \"%s\", buf);\n+\t\tstrlcpy(valid_socket_mem, buf, sizeof(valid_socket_mem));\n \n \t\tif (num_sockets - i > 1) {\n \t\t\tsnprintf(buf, sizeof(buf), \"%s,\", valid_socket_mem);\n-\t\t\tsnprintf(valid_socket_mem, sizeof(valid_socket_mem), \"%s\", buf);\n+\t\t\tstrlcpy(valid_socket_mem, buf,\n+\t\t\t\tsizeof(valid_socket_mem));\n \t\t}\n \t}\n \ndiff --git a/test/test/test_malloc.c b/test/test/test_malloc.c\nindex d23192cf1..ccc5feaec 100644\n--- a/test/test/test_malloc.c\n+++ b/test/test/test_malloc.c\n@@ -378,7 +378,7 @@ test_realloc(void)\n \t\tprintf(\"NULL pointer returned from rte_zmalloc\\n\");\n \t\treturn -1;\n \t}\n-\tsnprintf(ptr1, size1, \"%s\" ,hello_str);\n+\tstrlcpy(ptr1, hello_str, size1);\n \tchar *ptr2 = rte_realloc(ptr1, size2, RTE_CACHE_LINE_SIZE);\n \tif (!ptr2){\n \t\trte_free(ptr1);\n",
    "prefixes": [
        "dpdk-dev",
        "RFC"
    ]
}