Skip to contentSkip to conversation

thermal: core: Replace sprintf in thermal_bind_cdev_to_trip

PATCH In review Thorsten Blum 3 participants 3 messages Feb 23 – Mar 6 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: core: Replace sprintf in thermal_bind_cdev_to_trip

Replace unbounded sprintf() with the safer snprintf(). While the current code works correctly, snprintf() is safer and follows secure coding best practices. No functional changes.

---
 drivers/thermal/thermal_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/thermal_core.c +1 -1
index 17ca5c082643..89dd1666805f 100644
@@ -861,7 +861,7 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
 		goto free_mem;
 
 	dev->id = result;
-	sprintf(dev->name, "cdev%d", dev->id);
+	snprintf(dev->name, sizeof(dev->name), "cdev%d", dev->id);
 	result =
 	    sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
 	if (result)
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Thorsten Blum

Replace unbounded sprintf() with the safer snprintf(). While the current code works correctly, snprintf() is safer and follows secure coding best practices. No functional changes.

Agree

Quoted 11 lines
---
  drivers/thermal/thermal_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/thermal_core.c +0 -0
index 17ca5c082643..89dd1666805f 100644

drivers/thermal/thermal_core.c static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz, · line 867

Quoted 8 lines
drivers/thermal/thermal_core.c +1 -1
@@ -861,7 +861,7 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
  		goto free_mem;
 
  	dev->id = result;
-	sprintf(dev->name, "cdev%d", dev->id);
+	snprintf(dev->name, sizeof(dev->name), "cdev%d", dev->id);
  	result =
  	    sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
  	if (result)

LGTM, please add the tag and re-send so it's on top so faster to pick-up for merging

#2 lore raw
Quoted 34 lines · Lukasz Luba
Quoted 3 lines · Thorsten Blum

Replace unbounded sprintf() with the safer snprintf(). While the current code works correctly, snprintf() is safer and follows secure coding best practices. No functional changes.

Agree

Quoted 11 lines
---
  drivers/thermal/thermal_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/thermal_core.c +0 -0
index 17ca5c082643..89dd1666805f 100644

drivers/thermal/thermal_core.c static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz, · line 867

Quoted 8 lines
drivers/thermal/thermal_core.c +1 -1
@@ -861,7 +861,7 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
              goto free_mem;
 
      dev->id = result;
-     sprintf(dev->name, "cdev%d", dev->id);
+     snprintf(dev->name, sizeof(dev->name), "cdev%d", dev->id);
      result =
          sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
      if (result)

LGTM, please add the tag and re-send so it's on top so faster to pick-up for merging

Quoted 1 line

I've actually applied it already (as 7.1 material), thanks!