From: Amit Sunil Dhamne <amitsd@google.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: Maxwell Doose <m32285159@gmail.com>,
badhri@google.com, heikki.krogerus@linux.intel.com,
gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: typec: tcpm: replace strcpy with strscpy
Date: Mon, 4 May 2026 11:09:25 -0700 [thread overview]
Message-ID: <ad51b3a7-341b-4549-bb14-04260c35f999@google.com> (raw)
In-Reply-To: <20260429095445.11b7302e@pumpkin>
Hi David,
On 4/29/26 1:54 AM, David Laight wrote:
> On Thu, 23 Apr 2026 12:23:09 -0700
> Amit Sunil Dhamne <amitsd@google.com> wrote:
>
>> Hi Maxwell,
>>
>> On 4/19/26 2:36 PM, Maxwell Doose wrote:
>>> The function strcpy() is deprecated as it can be used in buffer overflow
>>> attacks. This patch replaces strcpy() with strscpy() to improve
>>> security and stability.
>>>
>>> Signed-off-by: Maxwell Doose <m32285159@gmail.com>
>>> ---
>>> drivers/usb/typec/tcpm/tcpm.c | 6 +++---
>>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
>>> index 8e0e14a2704e..69574c5e79e1 100644
>>> --- a/drivers/usb/typec/tcpm/tcpm.c
>>> +++ b/drivers/usb/typec/tcpm/tcpm.c
>>> @@ -725,7 +725,7 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
>>>
>>> if (tcpm_log_full(port)) {
>>> port->logbuffer_head = max(port->logbuffer_head - 1, 0);
>>> - strcpy(tmpbuffer, "overflow");
>>> + strscpy(tmpbuffer, "overflow", sizeof(tmpbuffer))
>>> }
>>>
>>> if (port->logbuffer_head < 0 ||
>>> @@ -841,10 +841,10 @@ static void tcpm_log_source_caps(struct tcpm_port *port)
>>> pdo_spr_avs_apdo_15v_to_20v_max_current_ma(pdo),
>>> pdo_spr_avs_apdo_src_peak_current(pdo));
>>> else
>>> - strcpy(msg, "undefined APDO");
>>> + strscpy(msg, "undefined APDO", sizeof(msg));
>>> break;
>>> default:
>>> - strcpy(msg, "undefined");
>>> + strscpy(msg, "undefined", sizeof(msg));
>>> break;
>>> }
>>> tcpm_log(port, " PDO %d: type %d, %s",
>> This has already been fixed as part of [1].
> It is also 'not a fix'.
> strcpy() is fine for copying literal strings into arrays.
> With the kernel headers you get a compile error from strcpy() if the string
> is too long.
> OTOH strscpy() will truncate overlong strings.
Thanks for the explanation :) .
> David
>
>> [1] https://patch.msgid.link/20260310094434.3639602-5-aichao@kylinos.cn
>>
>>
>> BR,
>>
>> Amit
>>
>>
next prev parent reply other threads:[~2026-05-04 18:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-19 21:36 [PATCH] usb: typec: tcpm: replace strcpy with strscpy Maxwell Doose
2026-04-23 19:23 ` Amit Sunil Dhamne
2026-04-23 20:56 ` Maxwell Doose
2026-04-29 8:54 ` David Laight
2026-05-04 18:09 ` Amit Sunil Dhamne [this message]
2026-04-27 23:01 ` kernel test robot
2026-04-28 23:11 ` kernel test robot
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=ad51b3a7-341b-4549-bb14-04260c35f999@google.com \
--to=amitsd@google.com \
--cc=badhri@google.com \
--cc=david.laight.linux@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=m32285159@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