From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f47.google.com (mail-pg0-f47.google.com [74.125.83.47]) by dpdk.org (Postfix) with ESMTP id AFAFE5598 for ; Wed, 21 Feb 2018 00:02:03 +0100 (CET) Received: by mail-pg0-f47.google.com with SMTP id f6so7708828pgs.10 for ; Tue, 20 Feb 2018 15:02:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PkWuaQv5n0GqGLHWJ0nYiWW5kb0Ll2x5ABVg0ZVKSss=; b=bntaPHooVTEgja+RxVuHNBQgYyb6y5IGJdM5xNvNyMLjkTe9MikRqyfjNFXBqVHrII q8at6rPFBGiXacf3UgC2ykZAIeF1xIn/fEaD/h3EMPMtmy01J+lWRM5J1Gd8OByS5utw 0dP8GW6TBtxU7LaWmQVwBkWoJFSZ8dyEQCI8qQEu/mJE46ndKUWcSJQLeAa5p3z+Drf9 D4/J1nqoXslCk3i8koimByDw41sSAD34ZVgl0o99quC2hIcg8XqeBsWfbXN4PHyekIgr BK47x85Y0K4Pg8J3wTAw++VdOnsBvbVHnkjl2oBeEH6E1aERdNTuYxTOaJzMw/KJGH1b vMQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PkWuaQv5n0GqGLHWJ0nYiWW5kb0Ll2x5ABVg0ZVKSss=; b=UnI9LGnuAmhUSSG6faFl+ZtXmXxuK2qw6IC4NLF9uCON58nxw1GbWlWev0DJ7Vy+Dt /fpHUgc0HdFpOjLXzGL+tykwL/brHXw8ihT24Vuh10J8JmLO6nbcai6f7vuLDE0f/fcl oeHht7EVckkrH865Te6qrODkOG0hnA9sVkpJQRSrL9s/0EsFtiBmJ7nX/wysxaCyh6tz L+cRWm4WshqdECmfztXIjTAWfhBqYLkDQ8ClCfaoJkAHmYuET1BEK/hUF+O6aRLpTjEq gfmRlAyO/SH+80DsqLaOd6+y+bDmuDDXiQ8hJKS7q7Z0sr5DjiYi9/EoHqv9HHk+N+7W 6Npg== X-Gm-Message-State: APf1xPD6zHRIHejd1saCvZ8snMdO4nTygUrhpQoOpDQYgn+IEok7/5PM j5JA8sIJCFnGhL4gx5/6TBqx8g== X-Google-Smtp-Source: AH8x224RjQZUUR1Z/kTWKh8EVkpZrhK/HcMqkZ5FB9IaEofthUAATiuiYoR3eRpGy/6QQbN5oWzbkQ== X-Received: by 10.98.63.147 with SMTP id z19mr1131077pfj.221.1519167722453; Tue, 20 Feb 2018 15:02:02 -0800 (PST) Received: from xeon-e3 (204-195-71-95.wavecable.com. [204.195.71.95]) by smtp.gmail.com with ESMTPSA id z6sm53435862pgu.49.2018.02.20.15.02.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Feb 2018 15:02:02 -0800 (PST) Date: Tue, 20 Feb 2018 15:01:53 -0800 From: Stephen Hemminger To: Bruce Richardson Cc: dev@dpdk.org Message-ID: <20180220150153.1ba35bba@xeon-e3> In-Reply-To: <20180220170727.220340-1-bruce.richardson@intel.com> References: <20180220170727.220340-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [RFC PATCH] use strlcpy for string copies 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: , X-List-Received-Date: Tue, 20 Feb 2018 23:02:03 -0000 On Tue, 20 Feb 2018 17:07:27 +0000 Bruce Richardson wrote: > Following on from the number of patches needing to be done for strncpy > issues highlighted by coverity... > > The strncpy function is error prone for doing "safe" string copies, so > we generally try to use "snprintf" instead in the code. The function > "strlcpy" is a better alternative, though, since it better conveys the > intention of the programmer, and doesn't suffer from the non-null > terminating behaviour of it's n'ed brethern. > > The downside of this function is that it is not available by default > on linux, though standard in the BSD's. It is available on most > distros by installing "libbsd" package. > > This RFC therefore provides the following in rte_string_fns.h to ensure > that strlcpy is available there: > * for BSD, include string.h as normal > * if RTE_USE_LIBBSD is set, include > * if not set, fallback to snprintf for strlcpy > > Using make build system, the RTE_USE_LIBBSD is a hard-coded value to "n", > but when using meson, it's automatically set based on what is available > on the platform. > > Instances of snprintf using "%s" alone as a string format are replaced > via coccinelle script with the new strlcpy function. Instances of > strncpy should be replaced too, but requires manual checking as to > whether the NULL termination is manually done afterward or not. > > Signed-off-by: Bruce Richardson Looks good, especially not reinventing strlcpy and using libbsd. Reviewed-by: Stephen Hemminger