Skip to contentSkip to conversation

media: siano: Replace strlcat() with snprintf() in sms_ir_init()

PATCH Superseded Mariia Nikitash 5 participants 14 messages Nov 4 – Nov 12 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: siano: Replace strlcat() with snprintf() in sms_ir_init()

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

Both the source and destination buffers have the same capacity, and the return values are unused. This preserves the resulting string, including truncation behavior.

---
 drivers/media/common/siano/smsir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/common/siano/smsir.c +2 -2
index 283770d583d5..636ff228108b 100644
@@ -55,8 +55,8 @@ int sms_ir_init(struct smscore_device_t *coredev)
 	snprintf(coredev->ir.name, sizeof(coredev->ir.name),
 		 "SMS IR (%s)", sms_get_board(board_id)->name);
 
-	strscpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
-	strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
+	snprintf(coredev->ir.phys, sizeof(coredev->ir.phys),
+		 "%s/ir0", coredev->devpath);
 
 	dev->device_name = coredev->ir.name;
 	dev->input_phys = coredev->ir.phys;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Mariia,

Quoted 8 lines

Date: 2026-11-04 01:02:39-0800
From: Mariia Nikitash <[email protected]>

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

Both the source and destination buffers have the same capacity,

The line above seems irrelevant, and potentially confusing. The size of the input is not important, because since we're appending stuff after it, truncation may actually happen.

Quoted 5 lines

and the return values are unused. This preserves the resulting string, including truncation behavior.

Except for the small comment above,

Cheers,
Alex

Quoted 23 lines
---
 drivers/media/common/siano/smsir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/common/siano/smsir.c +2 -2
index 283770d583d5..636ff228108b 100644
@@ -55,8 +55,8 @@ int sms_ir_init(struct smscore_device_t *coredev)
 	snprintf(coredev->ir.name, sizeof(coredev->ir.name),
 		 "SMS IR (%s)", sms_get_board(board_id)->name);
 
-	strscpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
-	strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
+	snprintf(coredev->ir.phys, sizeof(coredev->ir.phys),
+		 "%s/ir0", coredev->devpath);
 
 	dev->device_name = coredev->ir.name;
 	dev->input_phys = coredev->ir.phys;
Signature · 1 line
2.43.0
Signature · 1 line
<https://www.alejandro-colomar.es>
#2 lore raw
Quoted 2 lines · Alejandro Colomar

Hi Mariia,

Hi Alejandro,

Quoted 8 lines
Quoted 8 lines

Date: 2026-11-04 01:02:39-0800
From: Mariia Nikitash <[email protected]>

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

Quoted 5 lines
Quoted 1 line

Both the source and destination buffers have the same capacity,

The line above seems irrelevant, and potentially confusing. The size of the input is not important, because since we're appending stuff after it, truncation may actually happen.

Agreed. I've removed the statement about buffer capacities from the commit message in v2. No code changes.

Quoted 11 lines
Quoted 6 lines

and the return values are unused. This preserves the resulting string, including truncation behavior.

Except for the small comment above,

Thanks for the review!

Quoted 4 lines

Cheers,
Alex

Best,
Mariia

Quoted 26 lines
Quoted 20 lines
---
 drivers/media/common/siano/smsir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/common/siano/smsir.c +2 -3
index 283770d583d5..636ff228108b 100644
@@ -55,8 +55,8 @@ int sms_ir_init(struct smscore_device_t *coredev)
      snprintf(coredev->ir.name, sizeof(coredev->ir.name),
               "SMS IR (%s)", sms_get_board(board_id)->name);
 
-     strscpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
-     strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
+     snprintf(coredev->ir.phys, sizeof(coredev->ir.phys),
+              "%s/ir0", coredev->devpath);
 
      dev->device_name = coredev->ir.name;
      dev->input_phys = coredev->ir.phys;
--
Quoted 3 lines

2.43.0

--
<https://www.alejandro-colomar.es>

#3 lore raw
In reply to Alejandro Colomar
Quoted 9 lines · On Wed, 4 Nov 2026 12:25:17 +0100 Alejandro Colomar…

Hi Mariia,

Quoted 7 lines

Date: 2026-11-04 01:02:39-0800
From: Mariia Nikitash <[email protected]>

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

Quoted 5 lines
Quoted 1 line

Both the source and destination buffers have the same capacity,

The line above seems irrelevant, and potentially confusing. The size of the input is not important, because since we're appending stuff after it, truncation may actually happen.

And gcc's stupid format overflow check is going to complain.

David

Quoted 39 lines
Quoted 6 lines

and the return values are unused. This preserves the resulting string, including truncation behavior.

Except for the small comment above,

Cheers,
Alex

Quoted 23 lines
---
 drivers/media/common/siano/smsir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/common/siano/smsir.c +2 -2
index 283770d583d5..636ff228108b 100644
@@ -55,8 +55,8 @@ int sms_ir_init(struct smscore_device_t *coredev)
 	snprintf(coredev->ir.name, sizeof(coredev->ir.name),
 		 "SMS IR (%s)", sms_get_board(board_id)->name);
 
-	strscpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
-	strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
+	snprintf(coredev->ir.phys, sizeof(coredev->ir.phys),
+		 "%s/ir0", coredev->devpath);
 
 	dev->device_name = coredev->ir.name;
 	dev->input_phys = coredev->ir.phys;
Signature · 1 line
2.43.0
#4 lore raw
Quoted 13 lines · David Laight
Quoted 9 lines · On Wed, 4 Nov 2026 12:25:17 +0100 Alejandro Colomar…

Hi Mariia,

Quoted 7 lines

Date: 2026-11-04 01:02:39-0800
From: Mariia Nikitash <[email protected]>

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Both the source and destination buffers have the same capacity,

The line above seems irrelevant, and potentially confusing. The size of the input is not important, because since we're appending stuff after it, truncation may actually happen.

And gcc's stupid format overflow check is going to complain.

Thanks for pointing this out! I initially tested with Clang, but reproduced the warning with GCC. I've switched to seq_buf for v3.

Quoted 3 lines

David

Best,
Mariia

Quoted 40 lines
Quoted 39 lines
Quoted 6 lines

and the return values are unused. This preserves the resulting string, including truncation behavior.

Except for the small comment above,

Cheers,
Alex

Quoted 23 lines
---
 drivers/media/common/siano/smsir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/common/siano/smsir.c +2 -3
index 283770d583d5..636ff228108b 100644
@@ -55,8 +55,8 @@ int sms_ir_init(struct smscore_device_t *coredev)
    snprintf(coredev->ir.name, sizeof(coredev->ir.name),
             "SMS IR (%s)", sms_get_board(board_id)->name);
 
-   strscpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
-   strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
+   snprintf(coredev->ir.phys, sizeof(coredev->ir.phys),
+            "%s/ir0", coredev->devpath);
 
    dev->device_name = coredev->ir.name;
    dev->input_phys = coredev->ir.phys;
--

2.43.0

A message that is not in the archive (sent off-list or not yet received): CAPDEY+X7q2yeWaa7J=Nre+pQqUa2C760Hh9NovdGNSQ=VsEr8w@mail.gmail.com

#6 lore raw
Quoted 17 lines · On Thu, 5 Nov 2026 17:44:00 -0800 Mariia Nikitash <[email protected]>…
Quoted 15 lines · David Laight
Quoted 11 lines · On Wed, 4 Nov 2026 12:25:17 +0100 Alejandro Colomar…

Hi Mariia,

Quoted 8 lines

Date: 2026-11-04 01:02:39-0800
From: Mariia Nikitash <[email protected]>

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

Both the source and destination buffers have the same capacity,

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

The line above seems irrelevant, and potentially confusing. The size of the input is not important, because since we're appending stuff after it, truncation may actually happen.

And gcc's stupid format overflow check is going to complain.

Thanks for pointing this out! I initially tested with Clang, but reproduced the warning with GCC. I've switched to seq_buf for v3.

That is entirely OTT.
Currently scnprintf() doesn't complain.

David

Quoted 51 lines
Quoted 4 lines

David

Best,
Mariia

Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

and the return values are unused. This preserves the resulting string, including truncation behavior.

Except for the small comment above,

Quoted 8 lines
Quoted 8 lines

Cheers,
Alex

Review

Quoted 5 lines
---
 drivers/media/common/siano/smsir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/media/common/siano/smsir.c

Quoted 8 lines
Quoted 8 lines

drivers/media/common/siano/smsir.c int sms_ir_init(struct smscore_device_t *coredev) · line 58

Quoted 8 lines

index 283770d583d5..636ff228108b 100644

drivers/media/common/siano/smsir.c +0 -1
@@ -55,8 +55,8 @@ int sms_ir_init(struct smscore_device_t *coredev)
    snprintf(coredev->ir.name, sizeof(coredev->ir.name),
             "SMS IR (%s)", sms_get_board(board_id)->name);
 
-   strscpy(coredev->ir.phys, coredev->devpath,  

sizeof(coredev->ir.phys));

Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
drivers/media/common/siano/smsir.c +2 -2
-   strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
+   snprintf(coredev->ir.phys, sizeof(coredev->ir.phys),
+            "%s/ir0", coredev->devpath);
 
    dev->device_name = coredev->ir.name;
    dev->input_phys = coredev->ir.phys;
--

2.43.0

#7 lore raw
Quoted 24 lines · David Laight
Quoted 21 lines · On Thu, 5 Nov 2026 17:44:00 -0800 Mariia Nikitash <[email protected]>…
Quoted 19 lines · David Laight
Quoted 14 lines · On Wed, 4 Nov 2026 12:25:17 +0100 Alejandro Colomar…

Hi Mariia,

Quoted 8 lines

Date: 2026-11-04 01:02:39-0800
From: Mariia Nikitash <[email protected]>

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

Both the source and destination buffers have the same capacity,

The line above seems irrelevant, and potentially confusing. The size of the input is not important, because since we're appending stuff after it, truncation may actually happen.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

And gcc's stupid format overflow check is going to complain.

Thanks for pointing this out! I initially tested with Clang, but reproduced the warning with GCC. I've switched to seq_buf for v3.

That is entirely OTT.
Currently scnprintf() doesn't complain.

What does GCC say about it? Is it mad about src >= dest length but the format adds chars?

I agree that seq_buf isn't needed here; that's really only for complicated cases where the simpler solutions don't fit. (In this case, snprintf-like is best.)

Both seq_buf and scnprintf avoid the warning because GCC just happens to not recognize the pattern when using those helpers, so this is just silencing the warning, much like strlcat() did too.

Truncation was the norm already, so scnprintf is probably the best fit, but I think it may be worth looking at the surrounding code and conventions to decide if truncation should be communicated upward to the caller (i.e. fail), or if the structures involved should be adjusted to avoid truncation chance, etc etc. If possible we should avoid the weakness, but if not, just use the minimal solution here, which is scnprintf, though that kicks the warning down the road...

-Kees

Signature · 1 line
Kees Cook
#8 lore raw
Quoted 28 lines · Kees Cook
Quoted 24 lines · David Laight
Quoted 21 lines · On Thu, 5 Nov 2026 17:44:00 -0800 Mariia Nikitash <[email protected]>…
Quoted 19 lines · David Laight
Quoted 14 lines · On Wed, 4 Nov 2026 12:25:17 +0100 Alejandro Colomar…

Hi Mariia,

Quoted 8 lines

Date: 2026-11-04 01:02:39-0800
From: Mariia Nikitash <[email protected]>

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

Both the source and destination buffers have the same capacity,

The line above seems irrelevant, and potentially confusing. The size of the input is not important, because since we're appending stuff after it, truncation may actually happen.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

And gcc's stupid format overflow check is going to complain.

Thanks for pointing this out! I initially tested with Clang, but reproduced the warning with GCC. I've switched to seq_buf for v3.

That is entirely OTT.
Currently scnprintf() doesn't complain.

Hi Kees,

Quoted 1 line

What does GCC say about it? Is it mad about src >= dest length but the format adds chars?

GCC 13 reported -Wformat-truncation:

error: ‘/ir0’ directive output may be truncated writing 4 bytes into a region of size between 1 and 32

note: ‘snprintf’ output between 5 and 36 bytes
into a destination of size 32

Both devpath and ir.phys are 32-byte buffers, so the suffix may not fit.

Quoted 1 line

I agree that seq_buf isn't needed here; that's really only for complicated cases where the simpler solutions don't fit. (In this case, snprintf-like is best.)

That makes sense.

Quoted 3 lines

Both seq_buf and scnprintf avoid the warning because GCC just happens to not recognize the pattern when using those helpers, so this is just silencing the warning, much like strlcat() did too.

Truncation was the norm already, so scnprintf is probably the best fit, but I think it may be worth looking at the surrounding code and conventions to decide if truncation should be communicated upward to the caller (i.e. fail), or if the structures involved should be adjusted to avoid truncation chance, etc etc. If possible we should avoid the weakness, but if not, just use the minimal solution here, which is scnprintf, though that kicks the warning down the road...

I traced the USB/SDIO initialization paths and checked the caller's error handling. The existing code permits truncation, so I kept v4 focused on preserving that behavior with scnprintf(). Any broader changes to truncation handling could be addressed separately.

Thank you!

Quoted 4 lines

-Kees

Mariia

Quoted 2 lines

--
Kees Cook

Reviewed-by on v1 1/1
#9 lore raw
In reply to Mariia Nikitash
Quoted 10 lines · Mariia Nikitash

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

Both the source and destination buffers have the same capacity, and the return values are unused. This preserves the resulting string, including truncation behavior.

#10 lore raw

PATCH v2 1/1 media: siano: Replace strlcat() with snprintf() in sms_ir_init()

In reply to Mariia Nikitash

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single snprintf() call to construct the IR device path.

The return values are unused. This preserves the resulting string, including truncation behavior.

---

Changes in v2:
- No code changes.
- Remove the statement about buffer capacities
from the commit message.
- Add Reviewed-by tags from Alejandro Colomar and Shihuang Liu.

 drivers/media/common/siano/smsir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/common/siano/smsir.c +2 -2
index 283770d583d5..636ff228108b 100644
@@ -55,8 +55,8 @@ int sms_ir_init(struct smscore_device_t *coredev)
 	snprintf(coredev->ir.name, sizeof(coredev->ir.name),
 		 "SMS IR (%s)", sms_get_board(board_id)->name);
 
-	strscpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
-	strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
+	snprintf(coredev->ir.phys, sizeof(coredev->ir.phys),
+		 "%s/ir0", coredev->devpath);
 
 	dev->device_name = coredev->ir.name;
 	dev->input_phys = coredev->ir.phys;
Signature · 1 line
2.43.0
#11 lore raw

PATCH v4 1/1 media: siano: Replace strlcat() with scnprintf() in sms_ir_init()

In reply to Mariia Nikitash

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single bounded scnprintf() call to construct the IR device path.

This preserves the original NUL-terminated output, including partial or omitted "/ir0" suffixes when the 32-byte buffer is too small.

---
Changes in v4:
- Replace seq_buf with scnprintf(), as suggested by David Laight and Kees Cook.
- Remove the unused seq_buf include and local variable.

Changes in v3:
- Replace snprintf() with seq_buf operations after reproducing the GCC -Wformat-truncation warning noted by David Laight.
- Drop the previous Reviewed-by tags due to the implementation change.

Changes in v2:
- No code changes.
- Remove the statement about buffer capacities from the commit message.
- Add Reviewed-by tags from Alejandro Colomar and Shihuang Liu.

 drivers/media/common/siano/smsir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/common/siano/smsir.c +2 -2
index 283770d583d5..6952871c5816 100644
@@ -55,8 +55,8 @@ int sms_ir_init(struct smscore_device_t *coredev)
 	snprintf(coredev->ir.name, sizeof(coredev->ir.name),
 		 "SMS IR (%s)", sms_get_board(board_id)->name);
 
-	strscpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
-	strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
+	scnprintf(coredev->ir.phys, sizeof(coredev->ir.phys),
+		  "%s/ir0", coredev->devpath);
 
 	dev->device_name = coredev->ir.name;
 	dev->input_phys = coredev->ir.phys;
Signature · 1 line
2.43.0
Reviewed-by on v4 1/1
#12 lore raw

Re: [PATCH v4] media: siano: Replace strlcat() with scnprintf() in sms_ir_init()

Quoted 7 lines

Date: 2026-11-06 19:39:28-0800
From: Mariia Nikitash <[email protected]>

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single bounded scnprintf() call to construct the IR device path.

Quoted 5 lines

This preserves the original NUL-terminated output, including partial or omitted "/ir0" suffixes when the 32-byte buffer is too small.

Cheers,
Alex

Quoted 38 lines

---
Changes in v4:
- Replace seq_buf with scnprintf(), as suggested by David Laight and Kees Cook.
- Remove the unused seq_buf include and local variable.

Changes in v3:
- Replace snprintf() with seq_buf operations after reproducing the GCC -Wformat-truncation warning noted by David Laight.
- Drop the previous Reviewed-by tags due to the implementation change.

Changes in v2:
- No code changes.
- Remove the statement about buffer capacities from the commit message.
- Add Reviewed-by tags from Alejandro Colomar and Shihuang Liu.

 drivers/media/common/siano/smsir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/common/siano/smsir.c +2 -2
index 283770d583d5..6952871c5816 100644
@@ -55,8 +55,8 @@ int sms_ir_init(struct smscore_device_t *coredev)
 	snprintf(coredev->ir.name, sizeof(coredev->ir.name),
 		 "SMS IR (%s)", sms_get_board(board_id)->name);
 
-	strscpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
-	strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
+	scnprintf(coredev->ir.phys, sizeof(coredev->ir.phys),
+		  "%s/ir0", coredev->devpath);
 
 	dev->device_name = coredev->ir.name;
 	dev->input_phys = coredev->ir.phys;
Signature · 1 line
2.43.0
Signature · 1 line
<https://www.alejandro-colomar.es>
Tested-by on v4 1/1
#13 lore raw

Re: [PATCH v4] media: siano: Replace strlcat() with scnprintf() in sms_ir_init()

In reply to Mariia Nikitash
Quoted 9 lines · Mariia Nikitash

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single bounded scnprintf() call to construct the IR device path.

This preserves the original NUL-terminated output, including partial or omitted "/ir0" suffixes when the 32-byte buffer is too small.

Reviewed-by on v4 1/1
#14 lore raw

Re: [PATCH v4] media: siano: Replace strlcat() with scnprintf() in sms_ir_init()

In reply to Mariia Nikitash
Quoted 9 lines · Mariia Nikitash

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with a single bounded scnprintf() call to construct the IR device path.

This preserves the original NUL-terminated output, including partial or omitted "/ir0" suffixes when the 32-byte buffer is too small.

Thanks for the revisions! :)

Signature · 1 line
Kees Cook