From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9A78AA04F1 for ; Mon, 6 Jan 2020 12:49:20 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 751D61D59D; Mon, 6 Jan 2020 12:49:20 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 921DC1D59D for ; Mon, 6 Jan 2020 12:49:18 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jan 2020 03:49:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,402,1571727600"; d="scan'208";a="222814449" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.222.53]) by orsmga003.jf.intel.com with ESMTP; 06 Jan 2020 03:49:16 -0800 From: Ciara Power To: stable@dpdk.org Cc: maryam.tahhan@intel.com, reshma.pattan@intel.com, Ciara Power , romanx.korynkevych@intel.com Date: Mon, 6 Jan 2020 11:42:54 +0000 Message-Id: <20200106114254.54945-1-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-stable] [PATCH 17.11] app/proc_info: fix string copying to use strlcpy X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" [ upstream commit 7edbf7ddfd7d2453afaad3b72666491d30b616af ] Replaced strncpy and strcpy with strlcpy. Using strlcpy is safe practice when copying strings, as it will include a null terminator. Cc: romanx.korynkevych@intel.com Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id") Reported-by: Reshma Pattan Signed-off-by: Ciara Power Acked-by: Bruce Richardson --- app/proc_info/main.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/proc_info/main.c b/app/proc_info/main.c index 2893bec69..caf4e48c0 100644 --- a/app/proc_info/main.c +++ b/app/proc_info/main.c @@ -196,7 +196,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; @@ -363,50 +363,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); } } -- 2.17.1