From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ferruh Yigit Subject: Re: [PATCH] drivers: fix to replace strcat with strncat Date: Mon, 14 Jan 2019 13:29:38 +0000 Message-ID: <4eefd77e-aaec-90ce-05df-f320dc01af66@intel.com> References: <1547445875-24601-1-git-send-email-tallurix.chaitanya.babu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: reshma.pattan@intel.com, rmody@marvell.com, shshaikh@marvell.com, beilei.xing@intel.com, qi.z.zhang@intel.com, pablo.de.lara.guarch@intel.com, declan.doherty@intel.com, stable@dpdk.org To: Chaitanya Babu Talluri , dev@dpdk.org, alejandro.lucero@netronome.com Return-path: In-Reply-To: <1547445875-24601-1-git-send-email-tallurix.chaitanya.babu@intel.com> Content-Language: en-US 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 1/14/2019 6:04 AM, Chaitanya Babu Talluri wrote: > Strcat does not check the destination length and there might be > chances of string overflow so insted of strcat, strncat is used. > > Fixes: 540a211084 ("bnx2x: driver core") > Fixes: e163c18a15 ("net/i40e: update ptype and pctype info") > Fixes: ef28aa96e5 ("net/nfp: support multiprocess") > Fixes: 6f4eec2565 ("test/crypto: enhance scheduler unit tests") > Cc: stable@dpdk.org > > Signed-off-by: Chaitanya Babu Talluri <...> > @@ -685,11 +687,11 @@ nfp_acquire_secondary_process_lock(struct nfp_pcie_user *desc) > * driver is used because that implies root user. > */ > home_path = getenv("HOME"); > - lockfile = calloc(strlen(home_path) + strlen(lockname) + 1, > + lockfile = calloc(LOCKFILE_HOME_PATH + strlen(lockname) + 1, > sizeof(char)); > > - strcat(lockfile, home_path); > - strcat(lockfile, "/.lock_nfp_secondary"); > + strncat(lockfile, home_path, LOCKFILE_HOME_PATH); > + strncat(lockfile, lockname, strlen(lockfile)); I guess this need to be 'LOCKFILE_HOME_PATH - strlen(lockfile) - 1' instead. But also this can be implemented as 'snprintf()' Since 'lockfile' allocated dynamically based on sizes of existing strings, using 'lockname' instead of "/.lock_nfp_secondary" will show that there won't be any overflow but tools still may be complaining about 'strcat' usage.