From patchwork Thu Sep 26 15:11:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Power, Ciara" X-Patchwork-Id: 59905 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6C0502C57; Thu, 26 Sep 2019 16:24:47 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id B74742C52; Thu, 26 Sep 2019 16:24:45 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Sep 2019 07:24:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,552,1559545200"; d="scan'208";a="214491276" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.223.206]) by fmsmga004.fm.intel.com with ESMTP; 26 Sep 2019 07:24:43 -0700 From: Ciara Power To: dev@dpdk.org Cc: Ciara Power , romanx.korynkevych@intel.com, vipin.varghese@intel.com, stable@dpdk.org Date: Thu, 26 Sep 2019 16:11:59 +0100 Message-Id: <20190926151159.19256-1-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] app/proc-info: fix string copying to use strlcpy X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Replaced strncpy and strcpy with strlcpy. Also replaced snprintf with strlcpy where applicable. Using strlcpy is safe practice when copying strings, as it will include a null terminator. Cc: romanx.korynkevych@intel.com Cc: vipin.varghese@intel.com Cc: stable@dpdk.org Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id") Fixes: 8a37f37fc243 ("app/procinfo: add --show-port") Reported-by: Reshma Pattan Signed-off-by: Ciara Power Acked-by: Bruce Richardson --- app/proc-info/main.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/proc-info/main.c b/app/proc-info/main.c index a89b51bb3..903921b0f 100644 --- a/app/proc-info/main.c +++ b/app/proc-info/main.c @@ -201,7 +201,7 @@ proc_info_preparse_args(int argc, char **argv) int err = gethostname(host_id, MAX_LONG_OPT_SZ-1); if (err) - strcpy(host_id, "unknown"); + strlcpy(host_id, "unknown", sizeof(host_id)); } return 0; @@ -396,50 +396,50 @@ static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len, if ((type_end != NULL) && (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) { if (strncmp(type_end, "_errors", strlen("_errors")) == 0) - strncpy(cnt_type, "if_rx_errors", cnt_type_len); + strlcpy(cnt_type, "if_rx_errors", cnt_type_len); else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0) - strncpy(cnt_type, "if_rx_dropped", cnt_type_len); + strlcpy(cnt_type, "if_rx_dropped", cnt_type_len); else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0) - strncpy(cnt_type, "if_rx_octets", cnt_type_len); + strlcpy(cnt_type, "if_rx_octets", cnt_type_len); else if (strncmp(type_end, "_packets", strlen("_packets")) == 0) - strncpy(cnt_type, "if_rx_packets", cnt_type_len); + strlcpy(cnt_type, "if_rx_packets", cnt_type_len); else if (strncmp(type_end, "_placement", strlen("_placement")) == 0) - strncpy(cnt_type, "if_rx_errors", cnt_type_len); + strlcpy(cnt_type, "if_rx_errors", cnt_type_len); else if (strncmp(type_end, "_buff", strlen("_buff")) == 0) - strncpy(cnt_type, "if_rx_errors", cnt_type_len); + strlcpy(cnt_type, "if_rx_errors", cnt_type_len); else /* Does not fit obvious type: use a more generic one */ - strncpy(cnt_type, "derive", cnt_type_len); + strlcpy(cnt_type, "derive", cnt_type_len); } else if ((type_end != NULL) && (strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) { if (strncmp(type_end, "_errors", strlen("_errors")) == 0) - strncpy(cnt_type, "if_tx_errors", cnt_type_len); + strlcpy(cnt_type, "if_tx_errors", cnt_type_len); else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0) - strncpy(cnt_type, "if_tx_dropped", cnt_type_len); + strlcpy(cnt_type, "if_tx_dropped", cnt_type_len); else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0) - strncpy(cnt_type, "if_tx_octets", cnt_type_len); + strlcpy(cnt_type, "if_tx_octets", cnt_type_len); else if (strncmp(type_end, "_packets", strlen("_packets")) == 0) - strncpy(cnt_type, "if_tx_packets", cnt_type_len); + strlcpy(cnt_type, "if_tx_packets", cnt_type_len); else /* Does not fit obvious type: use a more generic one */ - strncpy(cnt_type, "derive", cnt_type_len); + strlcpy(cnt_type, "derive", cnt_type_len); } else if ((type_end != NULL) && (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) { if (strncmp(type_end, "_filters", strlen("_filters")) == 0) - strncpy(cnt_type, "operations", cnt_type_len); + strlcpy(cnt_type, "operations", cnt_type_len); else if (strncmp(type_end, "_errors", strlen("_errors")) == 0) - strncpy(cnt_type, "errors", cnt_type_len); + strlcpy(cnt_type, "errors", cnt_type_len); else if (strncmp(type_end, "_filters", strlen("_filters")) == 0) - strncpy(cnt_type, "filter_result", cnt_type_len); + strlcpy(cnt_type, "filter_result", cnt_type_len); } else if ((type_end != NULL) && (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) { if (strncmp(type_end, "_errors", strlen("_errors")) == 0) - strncpy(cnt_type, "errors", cnt_type_len); + strlcpy(cnt_type, "errors", cnt_type_len); } else { /* Does not fit obvious type, or strrchr error: */ /* use a more generic type */ - strncpy(cnt_type, "derive", cnt_type_len); + strlcpy(cnt_type, "derive", cnt_type_len); } } @@ -1321,7 +1321,7 @@ main(int argc, char **argv) if (ret) printf("Error from rte_eal_cleanup(), %d\n", ret); - snprintf(bdr_str, MAX_STRING_LEN, " "); + strlcpy(bdr_str, " ", MAX_STRING_LEN); STATS_BDR_STR(50, bdr_str); return 0;