public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: "Nelson, Shannon" <shannon.nelson@amd.com>
To: Pranav Tyagi <pranav.tyagi03@gmail.com>
Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	skhan@linuxfoundation.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH] net: ipconfig: replace strncpy with strscpy_pad
Date: Thu, 10 Apr 2025 13:40:42 -0700	[thread overview]
Message-ID: <16bc3288-ede5-4777-aac4-60426aef1321@amd.com> (raw)
In-Reply-To: <CAH4c4jKm9ewfL3G7SAGokzGT3VpLaKWQrbrxcLAnb-G8_MUjSA@mail.gmail.com>

On 4/10/2025 12:59 PM, Pranav Tyagi wrote:
> 
> On Wed, Apr 9, 2025 at 3:14 AM Nelson, Shannon <shannon.nelson@amd.com> wrote:
>>
>> On 4/8/2025 11:57 AM, Pranav Tyagi wrote:
>>>
>>> Replace the deprecated strncpy() function with strscpy_pad() as the
>>> destination buffer is NUL-terminated and requires
>>> trailing NUL-padding
>>>
>>> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
>>
>> There should be a Fixes tag here, and usually we put the 'net' tree
>> indicator inside the tag, like this: [PATCH net]
>>
>>
>>> ---
>>>    net/ipv4/ipconfig.c | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
>>> index c56b6fe6f0d7..7c238d19328f 100644
>>> --- a/net/ipv4/ipconfig.c
>>> +++ b/net/ipv4/ipconfig.c
>>> @@ -1690,7 +1690,7 @@ static int __init ic_proto_name(char *name)
>>>                           *v = 0;
>>>                           if (kstrtou8(client_id, 0, dhcp_client_identifier))
>>>                                   pr_debug("DHCP: Invalid client identifier type\n");
>>> -                       strncpy(dhcp_client_identifier + 1, v + 1, 251);
>>> +                       strscpy_pad(dhcp_client_identifier + 1, v + 1, 251);
>>
>> The strncpy() action, as well as the memcpy() into
>> dhcp_client_identifier elsewhere, are not padding to the end, so I think
>> this only needs to be null-terminated, not fully padded.  If full
>> padding is needed, please let us know why.
>>
>> sln
>>
>>>                           *v = ',';
>>>                   }
>>>                   return 1;
>>> --
>>> 2.49.0
>>>
>>>
>>
> 
> My initial assumption was on the fact that dhcp_client_identifier
> is directly used in DHCP packet construction
> and may be parsed byte-wise. But on going through the code again
> I see that it does not require to be fully padded.
> Would strscpy() suffice? as it ensures null-termination and
> does not fully pad the buffer.

Yes, strscpy() should work.
sln


> 
> Regards
> Pranav Tyagi


  reply	other threads:[~2025-04-10 20:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 18:57 [PATCH] net: ipconfig: replace strncpy with strscpy_pad Pranav Tyagi
2025-04-08 21:44 ` Nelson, Shannon
2025-04-10 19:59   ` Pranav Tyagi
2025-04-10 20:40     ` Nelson, Shannon [this message]
2025-04-10 20:05   ` Simon Horman

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=16bc3288-ede5-4777-aac4-60426aef1321@amd.com \
    --to=shannon.nelson@amd.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pranav.tyagi03@gmail.com \
    --cc=skhan@linuxfoundation.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