From patchwork Thu Jun 1 15:00:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 127841 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6DCF442C04; Thu, 1 Jun 2023 17:01:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BAF7D42D20; Thu, 1 Jun 2023 17:01:15 +0200 (CEST) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mails.dpdk.org (Postfix) with ESMTP id 6DDA442D17 for ; Thu, 1 Jun 2023 17:01:14 +0200 (CEST) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1b00ecabdf2so8737985ad.2 for ; Thu, 01 Jun 2023 08:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1685631673; x=1688223673; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5V4zO97PRtEsq4DvATu6DdzyIxNiLY8Nd1F9AOpOLO4=; b=g7toQa3ISlZVCbmJOGdHKTkNZ8/HXbWhn4uLU0yhbU+IrCt8+4h5ezxQPMusJZCUfR NupFFGWy50nh0pyhHY1IhgOkvjJ6jji9qNT48Lj4bQj7Zw1iWGf7NeADFssXzoN+/Cd/ Ko27YylHc0pNVIv28Q1h5CxjmEep+MhHQVchwfxOJhoAGjWl4OY4mI5l0qNoQPQCJSsC +rPH9QSTAcgNMN6eMQMJY+mixee9yFl+YN6MvtR0rAq75X+vdA5uZN82Id+iHsr+IFoh wCue/bjONC0wMwmbrBlp1wBP6wllj6uCGfa6NoUFS6SysSJva4WoEJk/q3r59igCA7hT 5j6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685631673; x=1688223673; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5V4zO97PRtEsq4DvATu6DdzyIxNiLY8Nd1F9AOpOLO4=; b=WRLUXq3qG5F627ieIh4336UU56LQ8ECSPP+fv0mH7umG4cCQmHZKSa+RyjqrGRkT8Q Vw2lf6mMsSXrCru0RUNzfq7zSqduQz3sncWVFUrDcxpR61IRgBKeB81vDMw89LWMZH6I kbgPLaO/5b/AtkP295ZyXwHGCG6Yuf6nyJ68OajmnwdZ/l858vKyQ3Tubf7ezgID1XmW gYmRWW2LZvD4O78GGP6shtt/S3zdnL0MuYH5SkzIYl+wVu2PVUpqjL2iGVgdWAbhGCR1 xsVJYNjtPFyjrkzaiaKhs1WjfHvy2kZrI0nhMxMH/kr98VwQDhAve/lxlbqq09g4aiFL 9n2Q== X-Gm-Message-State: AC+VfDyPxPvK6P6z1/nm2Orj3ek70SHRfKQOb2EVZpIi/b/t/ejeCGEa qx/8FKBqmkq6PT1l76WCqYL1RYlUZ/8UzVbzIdBzTw== X-Google-Smtp-Source: ACHHUZ6CDxJDanggNdDYs1+07D1z7baVcm78GKTZzedqECKTz8+IX6y54vEXj702FExGdZPZ022RrQ== X-Received: by 2002:a17:902:e849:b0:1ad:1c22:1b53 with SMTP id t9-20020a170902e84900b001ad1c221b53mr10280024plg.40.1685631673266; Thu, 01 Jun 2023 08:01:13 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id ij9-20020a170902ab4900b001ac40488620sm3661955plb.92.2023.06.01.08.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:01:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Nicolas Chautru , Ori Kam , Aman Singh , Yuying Zhang , Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram Subject: [PATCH 01/25] app: use strlcpy in tests Date: Thu, 1 Jun 2023 08:00:42 -0700 Message-Id: <20230601150106.18375-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601150106.18375-1-stephen@networkplumber.org> References: <20230601150106.18375-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Prefer using strlcpy over snprintf(). Signed-off-by: Stephen Hemminger --- app/test-bbdev/main.c | 5 ++--- app/test-pmd/cmdline_flow.c | 6 +++--- app/test/process.h | 2 +- app/test/test_graph_perf.c | 29 ++++++++++++++++------------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/test-bbdev/main.c b/app/test-bbdev/main.c index ec830eb32bc8..b1f2d79f4b07 100644 --- a/app/test-bbdev/main.c +++ b/app/test-bbdev/main.c @@ -251,9 +251,8 @@ parse_args(int argc, char **argv, struct test_params *tp) TEST_ASSERT(strlen(optarg) > 0, "Config file name is null"); - snprintf(tp->test_vector_filename, - sizeof(tp->test_vector_filename), - "%s", optarg); + strlcpy(tp->test_vector_filename, optarg, + sizeof(tp->test_vector_filename)); break; case 's': TEST_ASSERT(strlen(optarg) > 0, diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 58939ec321d6..40f67d126b4b 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -10028,7 +10028,7 @@ parse_hex_string(const char *src, uint8_t *dst, uint32_t *size) char tmp[3], *end = tmp; uint32_t read_lim = left & 1 ? 1 : 2; - snprintf(tmp, read_lim + 1, "%s", src); + strlcpy(tmp, src, read_lim + 1); *dst = strtoul(tmp, &end, 16); if (*end) { *dst = 0; @@ -11404,7 +11404,7 @@ cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size) if (!size) return -1; /* Set token type and update global help with details. */ - strlcpy(dst, (token->type ? token->type : "TOKEN"), size); + strlcpy(dst, token->type ? : "TOKEN", size); if (token->help) cmd_flow.help_str = token->help; else @@ -12220,7 +12220,7 @@ cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, if (!size) return -1; /* Set token type and update global help with details. */ - snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN")); + strlcpy(dst, token->type ? : "TOKEN", size); if (token->help) cmd_set_raw.help_str = token->help; else diff --git a/app/test/process.h b/app/test/process.h index 1f073b9c5c2a..e2bdecb9c807 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -176,7 +176,7 @@ get_current_prefix(char *prefix, int size) return NULL; /* get the prefix */ - snprintf(prefix, size, "%s", basename(dirname(buf))); + strlcpy(prefix, basename(dirname(buf)), size); return prefix; } diff --git a/app/test/test_graph_perf.c b/app/test/test_graph_perf.c index c5b463f700cd..521d4077600d 100644 --- a/app/test/test_graph_perf.c +++ b/app/test/test_graph_perf.c @@ -294,8 +294,9 @@ graph_node_count_edges(uint32_t stage, uint16_t node, uint16_t nodes_per_stage, for (i = 0; i < nodes_per_stage && edges < MAX_EDGES_PER_NODE; i++) { if (edge_map[stage + 1][i][node]) { ename[edges] = malloc(sizeof(char) * RTE_NODE_NAMESIZE); - snprintf(ename[edges], RTE_NODE_NAMESIZE, "%s", - rte_node_id_to_name(node_map[stage + 1][i])); + strlcpy(ename[edges], + rte_node_id_to_name(node_map[stage + 1][i]), + RTE_NODE_NAMESIZE); node_data->next_nodes[edges] = node_map[stage + 1][i]; node_data->next_percentage[edges] = edge_map[stage + 1][i][node]; @@ -405,9 +406,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks, graph_data->nb_nodes++; goto pattern_name_free; } - snprintf(node_patterns[graph_data->nb_nodes], - RTE_NODE_NAMESIZE, "%s", - rte_node_id_to_name(node_map[i][j])); + strlcpy(node_patterns[graph_data->nb_nodes], + rte_node_id_to_name(node_map[i][j]), + RTE_NODE_NAMESIZE); node_data = &graph_data->node_data[graph_data->nb_nodes]; node_data->node_id = node_map[i][j]; @@ -467,8 +468,8 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks, graph_data->nb_nodes++; goto pattern_name_free; } - snprintf(node_patterns[graph_data->nb_nodes], RTE_NODE_NAMESIZE, - "%s", rte_node_id_to_name(src_nodes[i])); + strlcpy(node_patterns[graph_data->nb_nodes], + rte_node_id_to_name(src_nodes[i]), RTE_NODE_NAMESIZE); node_data = &graph_data->node_data[graph_data->nb_nodes]; node_data->node_id = src_nodes[i]; node_data->is_sink = false; @@ -479,8 +480,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks, if (!src_map[i][j]) continue; ename[edges] = malloc(sizeof(char) * RTE_NODE_NAMESIZE); - snprintf(ename[edges], RTE_NODE_NAMESIZE, "%s", - rte_node_id_to_name(node_map[0][j])); + strlcpy(ename[edges], + rte_node_id_to_name(node_map[0][j]), + RTE_NODE_NAMESIZE); node_data->next_nodes[edges] = node_map[0][j]; node_data->next_percentage[edges] = src_map[i][j]; edges++; @@ -524,8 +526,8 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks, graph_data->nb_nodes++; goto pattern_name_free; } - snprintf(node_patterns[graph_data->nb_nodes], RTE_NODE_NAMESIZE, - "%s", rte_node_id_to_name(snk_nodes[i])); + strlcpy(node_patterns[graph_data->nb_nodes], + rte_node_id_to_name(snk_nodes[i]), RTE_NODE_NAMESIZE); node_data = &graph_data->node_data[graph_data->nb_nodes]; node_data->node_id = snk_nodes[i]; node_data->is_sink = true; @@ -543,8 +545,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks, if (!snk_map[i][j]) continue; ename[edges] = malloc(sizeof(char) * RTE_NODE_NAMESIZE); - snprintf(ename[edges], RTE_NODE_NAMESIZE, "%s", - rte_node_id_to_name(snk_nodes[j])); + strlcpy(ename[edges], + rte_node_id_to_name(snk_nodes[j]), + RTE_NODE_NAMESIZE); node_data->next_nodes[edges] = snk_nodes[j]; node_data->next_percentage[edges] = snk_map[i][j]; edges++;