netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kunwu Chan <kunwu.chan@linux.dev>
To: NeilBrown <neilb@suse.de>
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 <chentao@kylinos.cn>
Subject: Re: [PATCH] SUNRPC: Fix -Wformat-truncation warning
Date: Thu, 15 Aug 2024 16:30:20 +0800	[thread overview]
Message-ID: <0282be6f-e8ac-4428-a2ac-1ea6b7c25f4a@linux.dev> (raw)
In-Reply-To: <172363131189.6062.4199842989565550209@noble.neil.brown.name>

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 <chentao@kylinos.cn>
>>
>> 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 <chentao@kylinos.cn>
>> ---
>>   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


  reply	other threads:[~2024-08-15  8:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14  9:38 [PATCH] SUNRPC: Fix -Wformat-truncation warning kunwu.chan
2024-08-14 10:28 ` NeilBrown
2024-08-15  8:30   ` Kunwu Chan [this message]
2024-08-15 11:39     ` NeilBrown
2024-08-16  1:52       ` Kunwu Chan
2024-08-16 22:01 ` Andrew Lunn
2024-08-16 23:07   ` NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0282be6f-e8ac-4428-a2ac-1ea6b7c25f4a@linux.dev \
    --to=kunwu.chan@linux.dev \
    --cc=Dai.Ngo@oracle.com \
    --cc=anna@kernel.org \
    --cc=chentao@kylinos.cn \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jlayton@kernel.org \
    --cc=kolga@netapp.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).