public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Michael Straube <straube.linux@gmail.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	philipp.g.hortmann@gmail.com, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: rtl8192e: prefer strscpy over strncpy
Date: Fri, 25 Aug 2023 07:13:42 +0200	[thread overview]
Message-ID: <69226eca-d345-f6fa-59fe-3c55674cc534@gmail.com> (raw)
In-Reply-To: <cbca3311-2d5d-4b87-8966-e2b57d74d6e1@kadam.mountain>

On 8/10/23 07:01, Dan Carpenter wrote:
> On Wed, Aug 09, 2023 at 08:02:05PM +0200, Michael Straube wrote:
>> On 8/9/23 14:21, Greg KH wrote:
>>> On Sat, Aug 05, 2023 at 09:51:14AM +0200, Michael Straube wrote:
>>>> Replace strncpy with strscpy in two places where the destination buffer
>>>> should be NUL-terminated. Found by checkpatch.
>>>>
>>>> WARNING: Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90
>>>
>>> If a global search/replace could be done, it would have happend a long
>>> time ago.
>>>
>>> How was this tested?  The functions work differently, are you sure there
>>> is no change in functionality here?
>>>
>>
>> It was only compile tested. To me it looked as it does not change
>> functionality, but looking a bit deeper at it I'm not sure anymore.
>> So, we should leave it as is.
> 
> So there are three main differences between strncpy() and strcpy().
> 
> 1) The return.
> 2) strncpy() will always write net->hidden_ssid_len bytes.  If the
>     string to copy is smaller than net->hidden_ssid_len bytes it will
>     fill the rest with zeroes.  This can be important for preventing
>     information leaks.
> 3) strscpy() will always add a NUL terminator where strncpy() just
>     truncates a too long string without adding a terminator.
> 
> We want #3.  We don't care about #1.  The only thing to check is #2.
> 
> regards,
> dan carpenter
> 

Thank you Dan,

so in this case we should/could replace strncpy with strscpy_pad,
correct?

regards,
Michael

  reply	other threads:[~2023-08-25  5:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-05  7:51 [PATCH] staging: rtl8192e: prefer strscpy over strncpy Michael Straube
2023-08-09 12:21 ` Greg KH
2023-08-09 18:02   ` Michael Straube
2023-08-10  5:01     ` Dan Carpenter
2023-08-25  5:13       ` Michael Straube [this message]
2023-09-05  9:23         ` Dan Carpenter

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=69226eca-d345-f6fa-59fe-3c55674cc534@gmail.com \
    --to=straube.linux@gmail.com \
    --cc=dan.carpenter@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=philipp.g.hortmann@gmail.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