public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: typec: tcpm: replace strcpy with strscpy
@ 2026-04-19 21:36 Maxwell Doose
  2026-04-23 19:23 ` Amit Sunil Dhamne
  0 siblings, 1 reply; 3+ messages in thread
From: Maxwell Doose @ 2026-04-19 21:36 UTC (permalink / raw)
  To: badhri, heikki.krogerus, gregkh; +Cc: linux-usb, linux-kernel

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",
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: typec: tcpm: replace strcpy with strscpy
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Amit Sunil Dhamne @ 2026-04-23 19:23 UTC (permalink / raw)
  To: Maxwell Doose, badhri, heikki.krogerus, gregkh; +Cc: linux-usb, linux-kernel

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].

[1] https://patch.msgid.link/20260310094434.3639602-5-aichao@kylinos.cn


BR,

Amit


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: typec: tcpm: replace strcpy with strscpy
  2026-04-23 19:23 ` Amit Sunil Dhamne
@ 2026-04-23 20:56   ` Maxwell Doose
  0 siblings, 0 replies; 3+ messages in thread
From: Maxwell Doose @ 2026-04-23 20:56 UTC (permalink / raw)
  To: Amit Sunil Dhamne
  Cc: badhri, heikki.krogerus, gregkh, linux-usb, linux-kernel

On Thu, Apr 23, 2026 at 2:23 PM Amit Sunil Dhamne <amitsd@google.com> wrote:
>
> Hi Maxwell,
>
> This has already been fixed as part of [1].
>
> [1] https://patch.msgid.link/20260310094434.3639602-5-aichao@kylinos.cn
>

Ah, didn't see that. I'll go focus on other things for now then.

best regards,
maxwell

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-23 20:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox