From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752114AbdBOLyB (ORCPT ); Wed, 15 Feb 2017 06:54:01 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:37133 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752035AbdBOLx7 (ORCPT ); Wed, 15 Feb 2017 06:53:59 -0500 Subject: Re: [PATCH] greybus: fw-management: Replace strncpy with strlcpy To: "Tobin C. Harding" , greybus-dev@lists.linaro.org References: <1487117364-15423-1-git-send-email-me@tobin.cc> Cc: devel@driverdev.osuosl.org, Greg Kroah-Hartman , Johan Hovold , linux-kernel@vger.kernel.org From: "Bryan O'Donoghue" Message-ID: Date: Wed, 15 Feb 2017 11:53:57 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <1487117364-15423-1-git-send-email-me@tobin.cc> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/02/17 00:09, Tobin C. Harding wrote: > Greybus currently uses strncpy() coupled with a check for '\0' on the > last byte of various buffers. strncpy() is passed size parameter equal > to the size of the buffer in all instances. If the source string is > larger than the destination buffer the check catches this and, after > logging the error, returns an error value. In one instance the > immediate return is not required. Using strncpy() with the manual check > adds code that could be removed by the use of strlcpy(), although truncation > then needs to be checked. > > Replace calls to strncpy() with calls to strlcpy(). Replace null > termination checks with checks for truncated string. Add log message > if string is truncated but do not return an error code. The strlcpy() replace should be one patch. The not returning on truncation should be a separate patch. Personally I don't think the flow should change re: returning errors on string truncation but, either way you should split it up. --- bod