From: Thorsten Blum <thorsten.blum@linux.dev>
To: david laight <david.laight@runbox.com>
Cc: "David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] net: ipconfig: Replace strncpy with strscpy_pad in ic_proto_name
Date: Wed, 26 Nov 2025 15:45:50 +0100 [thread overview]
Message-ID: <B7B14C9F-C63B-4278-AA3F-12618681482A@linux.dev> (raw)
In-Reply-To: <20251126135042.06c1422b@pumpkin>
On 26. Nov 2025, at 14:50, david laight wrote:
> On Wed, 26 Nov 2025 12:13:58 +0100
> Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
>> strncpy() is deprecated [1] for NUL-terminated destination buffers since
>> it does not guarantee NUL termination. Replace it with strscpy_pad() to
>> ensure NUL termination of the destination buffer while retaining the
>> NUL-padding behavior of strncpy().
>>
>> Even though the identifier buffer has 252 usable bytes, strncpy()
>> intentionally copied only 251 bytes into the zero-initialized buffer,
>> implicitly relying on the last byte to act as the terminator. Switching
>> to strscpy_pad() removes the need for this trick and avoids using magic
>> numbers.
>>
>> The source string is also NUL-terminated and satisfies the
>> __must_be_cstr() requirement of strscpy_pad().
>>
>> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
>> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
>> ---
>> [...]
>
> Wrong change...
> There is no reason to pad the destination, and the correct alternative
I agree, padding isn't necessary and strscpy() is enough.
> is to bound 'v - client_id' and then use memcpy().
> Then you don't need to modify the input buffer.
Just to confirm - this comment is about the type parsing ('client_id'
before the comma), not about copying the value after the comma, right?
Thanks,
Thorsten
next prev parent reply other threads:[~2025-11-26 14:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 11:13 Thorsten Blum
2025-11-26 13:50 ` david laight
2025-11-26 14:45 ` Thorsten Blum [this message]
2025-11-26 18:44 ` david laight
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=B7B14C9F-C63B-4278-AA3F-12618681482A@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=davem@davemloft.net \
--cc=david.laight@runbox.com \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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
all inboxes | Powered by JetHome®