From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5AF2742C04; Thu, 1 Jun 2023 17:01:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D826C42D38; Thu, 1 Jun 2023 17:01:16 +0200 (CEST) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 3FEDF42D32 for ; Thu, 1 Jun 2023 17:01:16 +0200 (CEST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1b01d3bb571so4235445ad.2 for ; Thu, 01 Jun 2023 08:01:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1685631675; x=1688223675; 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=gIvha0+GOXub4tzHETH9R4qYWzELpkNT71kklhQwYlo=; b=hEMT5RGZpn3MtPKmGSBFliiRRmY8G14b2wQCxTR150FxOSaPmEACmzYGghejomwzSf 9loocmBfKj0n3j+FwKOxc0/Yd6tqpp3OcjhP0I5tYxx8NplEulzEYwoJZAsROjgDUgan U/YBu6wua0isiEF6/5C6mqBM6OyTc9dV+XhOaX26ubBWF8FFhp/F7BCjd/qEyeIcunjT zSxbjdryP8NaeClbKgYj7sDC9Xprrpr4g+ECtEr30HdR9/Mpmort4KcG1Us9uatF9trD RMqcDJoZdGuOLvFUAOzpmcHpRer/nrdSz9wg8UQrydwCrUpceZdFEz5oVl+TrQ738hg+ 0jzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685631675; x=1688223675; 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=gIvha0+GOXub4tzHETH9R4qYWzELpkNT71kklhQwYlo=; b=FrRxKIe4yVPaOLmN8lckg17SZVaL+M//9TDkfKRQeSdihJXRIlYHLH8eqv/2Ss+Sjt cA1m1h2QgI3C+etlStO2RI5J+0squ8kmlutc7IOe+meXxANmEUWnz4ngiuV4jizNQuPP NSayzNLdlkFWT2kPs2rwZ/21x75frfPJcOkSYs4mF+2Eqp2ytU4EARGuVFqM9tPWFcOO +MlvWDteuj1LEXfdOzI2i8HNBj2mmb3phreUihurPzTjk489Zx8wJYsbddq+jTv21lJs VI4bdv6joH0kGwT0txV1t+341K3cYCTGENmNflrtA93dqJJD++q5qkWzv2XPPgh6DvP7 jVpQ== X-Gm-Message-State: AC+VfDylGdIdKxEooLpItztV+s97k1ihPHUtoKpoUHFidAuzFSBBTXb3 SbasRsgPJBxmy8N7is12eGG9UzjvddyvnibyAZnjsA== X-Google-Smtp-Source: ACHHUZ6TFasnnPaCaLcFYKWvNUyTwQ45V7kAW2JXrYjjwgbRbDPKbahPZxPuQAXGUJCvafXx5jbXHw== X-Received: by 2002:a17:902:d4c4:b0:19f:8ad5:4331 with SMTP id o4-20020a170902d4c400b0019f8ad54331mr7602155plg.38.1685631675230; Thu, 01 Jun 2023 08:01:15 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:01:14 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Brian Dooley , Gowrishankar Muthukrishnan , Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Cristian Dumitrescu , Maxime Coquelin , Chenbo Xia Subject: [PATCH 02/25] examples: use strlcpy instead of snprintf Date: Thu, 1 Jun 2023 08:00:43 -0700 Message-Id: <20230601150106.18375-3-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 Content-Transfer-Encoding: 8bit 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 Replace snprintf() with strlcpy() where possible. Signed-off-by: Stephen Hemminger --- examples/fips_validation/fips_validation.c | 8 ++++---- examples/l3fwd-graph/main.c | 2 +- examples/pipeline/cli.c | 2 +- examples/vhost_blk/vhost_blk.c | 5 ++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index f840804009ed..6e913898074d 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -505,8 +505,8 @@ fips_test_parse_one_json_group(void) switch (json_typeof(param)) { case JSON_STRING: - snprintf(json_value, sizeof(json_value), "%s", - json_string_value(param)); + strlcpy(json_value, json_string_value(param), + sizeof(json_value)); break; case JSON_INTEGER: @@ -550,8 +550,8 @@ fips_test_parse_one_json_case(void) switch (json_typeof(param)) { case JSON_STRING: - snprintf(info.one_line_text, MAX_LINE_CHAR, "%s", - json_string_value(param)); + strlcpy(info.one_line_text, json_string_value(param), + MAX_LINE_CHAR); break; case JSON_INTEGER: diff --git a/examples/l3fwd-graph/main.c b/examples/l3fwd-graph/main.c index 5feeab4f0fb0..ee8f247108ad 100644 --- a/examples/l3fwd-graph/main.c +++ b/examples/l3fwd-graph/main.c @@ -546,7 +546,7 @@ parse_args(int argc, char **argv) break; case CMD_LINE_OPT_PCAP_FILENAME_CAP: - rte_strlcpy(pcap_filename, optarg, + strlcpy(pcap_filename, optarg, sizeof(pcap_filename)); printf("Pcap file name: %s\n", pcap_filename); break; diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c index 2ae6cc579ff2..514b6d779212 100644 --- a/examples/pipeline/cli.c +++ b/examples/pipeline/cli.c @@ -3164,7 +3164,7 @@ cmd_ipsec_sa_add(char **tokens, goto free; } - snprintf(out, out_size, "%s", line); + strlcpy(out, line, out_size); out_size -= strlen(out); out += strlen(out); diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c index 3709d7ed06ba..3b05df390cce 100644 --- a/examples/vhost_blk/vhost_blk.c +++ b/examples/vhost_blk/vhost_blk.c @@ -771,9 +771,8 @@ vhost_blk_bdev_construct(const char *bdev_name, if (!bdev) return NULL; - snprintf(bdev->name, sizeof(bdev->name), "%s", bdev_name); - snprintf(bdev->product_name, sizeof(bdev->product_name), "%s", - bdev_serial); + strlcpy(bdev->name, bdev_name, sizeof(bdev->name)); + strlcpy(bdev->product_name, bdev_serial, sizeof(bdev->product_name)); bdev->blocklen = blk_size; bdev->blockcnt = blk_cnt; bdev->write_cache = wce_enable; -- 2.39.2