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 B4E94A00E6 for ; Fri, 12 Jul 2019 16:48:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4C6171B9B2; Fri, 12 Jul 2019 16:48:00 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 36B9931FC; Fri, 12 Jul 2019 16:47:58 +0200 (CEST) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jul 2019 07:47:56 -0700 X-IronPort-AV: E=Sophos;i="5.63,482,1557212400"; d="scan'208";a="189854436" Received: from bricha3-mobl.ger.corp.intel.com ([10.237.221.51]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jul 2019 07:47:55 -0700 Date: Fri, 12 Jul 2019 15:47:51 +0100 From: Bruce Richardson To: David Hunt Cc: dev@dpdk.org, stable@dpdk.org Message-ID: <20190712144750.GB536@bricha3-MOBL.ger.corp.intel.com> References: <20190712140402.8492-1-david.hunt@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190712140402.8492-1-david.hunt@intel.com> User-Agent: Mutt/1.11.4 (2019-03-13) Subject: Re: [dpdk-dev] [PATCH v1] examples/vm_power: fix strcpy buffer overrun 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" On Fri, Jul 12, 2019 at 03:04:02PM +0100, David Hunt wrote: > replace strcpy with rte_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] > > Cc: stable@dpdk.org > Fixes: 59287933a0bb ("examples/vm_power: add options to guest app") > Signed-off-by: David Hunt > --- > examples/vm_power_manager/guest_cli/main.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > 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': > -- You can just use "strlcpy" without the "rte_" prefix. The rte_ version is just a fallback used when a standard strlcpy - either natively or from libbsd - is unavailable.