From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 66D97A0471
	for <public@inbox.dpdk.org>; Tue, 16 Jul 2019 10:24:14 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 383ED324D;
	Tue, 16 Jul 2019 10:24:14 +0200 (CEST)
Received: from mga17.intel.com (mga17.intel.com [192.55.52.151])
 by dpdk.org (Postfix) with ESMTP id 3B9A12BD5;
 Tue, 16 Jul 2019 10:24:09 +0200 (CEST)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga003.jf.intel.com ([10.7.209.27])
 by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 16 Jul 2019 01:24:08 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.63,497,1557212400"; d="scan'208";a="169865126"
Received: from silpixa00399952.ir.intel.com (HELO
 silpixa00399952.ger.corp.intel.com) ([10.237.222.88])
 by orsmga003.jf.intel.com with ESMTP; 16 Jul 2019 01:24:07 -0700
From: David Hunt <david.hunt@intel.com>
To: dev@dpdk.org
Cc: david.hunt@intel.com,
	stable@dpdk.org
Date: Tue, 16 Jul 2019 09:24:05 +0100
Message-Id: <20190716082405.22394-1-david.hunt@intel.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20190712140402.8492-1-david.hunt@intel.com>
References: <20190712140402.8492-1-david.hunt@intel.com>
Subject: [dpdk-stable] [PATCH v2] examples/vm_power: fix strcpy buffer
	overrun
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org
Sender: "stable" <stable-bounces@dpdk.org>

replace strcpy with strlcpy to prevent buffer overrun
With fix, attempting to use a VERY lonng vm name results in a nicely
truncated 32 character name rather than a segfault:
Setting VM Name to [sdfdsfsfsdffdsdsasdsadasdakjshd]

Using strlcpy rather than rte_strlcpy, as the rte_ version is only a
fallback.

As well as the fix in main.c, this patch also changes an occurrence of
rte_strlcpy in channel_manager.c and channel_monitor.c to strlcpy.

Fixes: 59287933a0bb ("examples/vm_power: add options to guest app")
Cc: stable@dpdk.org
Signed-off-by: David Hunt <david.hunt@intel.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 examples/vm_power_manager/channel_manager.c | 2 +-
 examples/vm_power_manager/channel_monitor.c | 2 +-
 examples/vm_power_manager/guest_cli/main.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 2c1332257..4db225755 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -588,7 +588,7 @@ add_host_channels(void)
 			goto error;
 		}
 		chan_infos[i] = chan_info;
-		rte_strlcpy(chan_info->channel_path, socket_path,
+		strlcpy(chan_info->channel_path, socket_path,
 				sizeof(chan_info->channel_path));
 
 		if (setup_host_channel_info(&chan_info, i) < 0) {
diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
index 9d7474da0..496772f8a 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -309,7 +309,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt,
 				vm_name);
 			return -1;
 		}
-		rte_strlcpy(pkt->vm_name, vm_name, VM_MAX_NAME_SZ);
+		strlcpy(pkt->vm_name, vm_name, VM_MAX_NAME_SZ);
 		pkt->resource_id = resource_id;
 	}
 	return 0;
diff --git a/examples/vm_power_manager/guest_cli/main.c b/examples/vm_power_manager/guest_cli/main.c
index 36365b124..a18eb214a 100644
--- a/examples/vm_power_manager/guest_cli/main.c
+++ b/examples/vm_power_manager/guest_cli/main.c
@@ -65,7 +65,7 @@ parse_args(int argc, char **argv)
 		switch (opt) {
 		/* portmask */
 		case 'n':
-			strcpy(policy->vm_name, optarg);
+			rte_strlcpy(policy->vm_name, optarg, VM_MAX_NAME_SZ);
 			printf("Setting VM Name to [%s]\n", policy->vm_name);
 			break;
 		case 'b':
-- 
2.17.1