From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28AB2177980 for ; Thu, 15 Aug 2024 08:30:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723710648; cv=none; b=f5E/8IyoInPSlO00m3NDRFJLwE+3SP5snNSEC94N2c+OtB3FiSfFsvELxU6NUqyvjzjJ7E0zZD2jTE30uVGyEkiyk3yFCH/ORlfWn3dWMUjX/r/ydbQQNvSaRO5s6K7hu2mJgEGhtiBNcMJ7DtfkNAY571i1GkQL2me87yeGB1c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723710648; c=relaxed/simple; bh=nl3MznZJdMVxI4LJ4em4IKdizm38EsySmGVIpcr66fw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=srqY4m+y69cs+ZXXqh/QLpVWCdcP7D55YXoHZ1mfYhF1SqFeGMGTJ27xUBRQujOEQ3PtRZWYhF7WNVasXKwnrGWAQ2VK9jXHN4A+6NkQK/2HUWDHPV2gdTrUYVk9eNhA1ut4qag6El6QwEaM+TN8SAyW4h8rTx/3+f0HnuLAfts= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QQ5kBSSU; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QQ5kBSSU" Message-ID: <0282be6f-e8ac-4428-a2ac-1ea6b7c25f4a@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1723710642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H46cTvBqsMii2CYcoZMIb49w/3n4/lbMyRjfJLUdJ2Y=; b=QQ5kBSSUL/fpningt+lddUKbZtmay4Op1qrYDO1/87pza2jcYIc7WLCb1I3KId3gx/Y21J MeEc4lJHD0snpaw9tVRGOABPPFW8MDsbkJ3N3EnRcy4782lC6efr73WO/6PLdrKIsbjnno W8Gx4HYxvt5aORCsrhqVxaQGT1LlpTA= Date: Thu, 15 Aug 2024 16:30:20 +0800 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] SUNRPC: Fix -Wformat-truncation warning To: NeilBrown Cc: trondmy@kernel.org, anna@kernel.org, chuck.lever@oracle.com, jlayton@kernel.org, kolga@netapp.com, Dai.Ngo@oracle.com, tom@talpey.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan References: <20240814093853.48657-1-kunwu.chan@linux.dev> <172363131189.6062.4199842989565550209@noble.neil.brown.name> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kunwu Chan In-Reply-To: <172363131189.6062.4199842989565550209@noble.neil.brown.name> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Thanks for your reply. On 2024/8/14 18:28, NeilBrown wrote: > On Wed, 14 Aug 2024, kunwu.chan@linux.dev wrote: >> From: Kunwu Chan >> >> Increase size of the servername array to avoid truncated output warning. >> >> net/sunrpc/clnt.c:582:75: error:‘%s’ directive output may be truncated >> writing up to 107 bytes into a region of size 48 >> [-Werror=format-truncation=] >> 582 | snprintf(servername, sizeof(servername), "%s", >> | ^~ >> >> net/sunrpc/clnt.c:582:33: note:‘snprintf’ output >> between 1 and 108 bytes into a destination of size 48 >> 582 | snprintf(servername, sizeof(servername), "%s", >> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> 583 | sun->sun_path); >> >> Signed-off-by: Kunwu Chan >> --- >> net/sunrpc/clnt.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c >> index 09f29a95f2bc..874085f3ed50 100644 >> --- a/net/sunrpc/clnt.c >> +++ b/net/sunrpc/clnt.c >> @@ -546,7 +546,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args) >> .connect_timeout = args->connect_timeout, >> .reconnect_timeout = args->reconnect_timeout, >> }; >> - char servername[48]; >> + char servername[108]; > If we choose this approach to removing the warning, then we should use > UNIX_PATH_MAX rather than 108. My negligence. > > However the longest server name copied in here will in practice be > /var/run/rpcbind.sock > > so the extra 60 bytes on the stack is wasted ... maybe that doesn't > matter. I'm thinking  about use a dynamic space alloc method like kasprintf to avoid space waste. > The string is only used by xprt_create_transport() which requires it to > be less than RPC_MAXNETNAMELEN - which is 256. > So maybe that would be a better value to use for the array size .... if > we assume that stack space isn't a problem. Thank you for the detailed explanation. I read the xprt_create_transport,  the RPC_MAXNETNAMELEN is only use to xprt_create_transport . > What ever number we use, I'd rather it was a defined constant, and not > an apparently arbitrary number. Whether we could check the sun->sun_path length before using snprintf?  The array size should smaller than  the minimum of sun->sun_path and RPC_MAXNETNAMELEN. Or use the dynamic space allocate method to save space. > > Thanks, > NeilBrown > > >> struct rpc_clnt *clnt; >> int i; >> >> -- >> 2.40.1 >> >> -- Thanks, Kunwu.Chan