[PATCH v3] staging: media: atomisp: replace sprintf() with strscpy()

tomasz.unger@yahoo.pl posted 1 patch 1 month, 1 week ago
drivers/staging/media/atomisp/pci/atomisp_subdev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v3] staging: media: atomisp: replace sprintf() with strscpy()
Posted by tomasz.unger@yahoo.pl 1 month, 1 week ago
From: Tomasz Unger <tomasz.unger@yahoo.pl>

Auditing calls to sprintf(). This code is fine because we are
copying 9 characters into a 52 character buffer. But it would
be cleaner to use strscpy() instead. Additionally, the 2-argument
version of strscpy() checks at compile time that dst is an array,
not just a pointer.

This is the only sprintf() call in the whole driver.

Signed-off-by: Tomasz Unger <tomasz.unger@yahoo.pl>
---
Changes since v2 (requested by Andy Shevchenko <andriy.shevchenko@intel.com>):
- Updated commit message: strscpy() 2-argument version also checks
  at compile time that dst is an array, not just a pointer
- Confirmed: this is the only sprintf() call in the whole driver
    
Changes since v1 (requested by Dan Carpenter <dan.carpenter@linaro.org>):
- Rewrite commit message to avoid misleading buffer overflow claims
- Testing information moved under --- as requested
    
Testing:
- make drivers/staging/media/atomisp/: compiled successfully, 0 errors, 0 warnings

 drivers/staging/media/atomisp/pci/atomisp_subdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_subdev.c b/drivers/staging/media/atomisp/pci/atomisp_subdev.c
index 3d56ca83ecb7..cef44ec9ebde 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_subdev.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_subdev.c
@@ -808,7 +808,7 @@ static int isp_subdev_init_entities(struct atomisp_sub_device *asd)
 	int ret;
 
 	v4l2_subdev_init(sd, &isp_subdev_v4l2_ops);
-	sprintf(sd->name, "Atom ISP");
+	strscpy(sd->name, "Atom ISP");
 	v4l2_set_subdevdata(sd, asd);
 	sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
 
-- 
2.53.0
Re: [PATCH v3] staging: media: atomisp: replace sprintf() with strscpy()
Posted by Dan Carpenter 1 month, 1 week ago
On Thu, Feb 26, 2026 at 12:16:53PM +0100, tomasz.unger@yahoo.pl wrote:
> From: Tomasz Unger <tomasz.unger@yahoo.pl>
> 
> Auditing calls to sprintf(). This code is fine because we are
> copying 9 characters into a 52 character buffer. But it would
> be cleaner to use strscpy() instead. Additionally, the 2-argument
> version of strscpy() checks at compile time that dst is an array,
> not just a pointer.
> 
> This is the only sprintf() call in the whole driver.
> 
> Signed-off-by: Tomasz Unger <tomasz.unger@yahoo.pl>
> ---

Thanks!

Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>

regards,
dan carpenter