Skip to content

Commit c996260

Browse files
Dan Carpenterrafaeljw
authored andcommitted
thermal: core: prevent potential string overflow
The dev->id value comes from ida_alloc() so it's a number between zero and INT_MAX. If it's too high then these sprintf()s will overflow. Fixes: 203d3d4 ("the generic thermal sysfs driver") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e17ea8a commit c996260

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/thermal/thermal_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,8 @@ int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
681681
if (result)
682682
goto release_ida;
683683

684-
sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
684+
snprintf(dev->attr_name, sizeof(dev->attr_name), "cdev%d_trip_point",
685+
dev->id);
685686
sysfs_attr_init(&dev->attr.attr);
686687
dev->attr.attr.name = dev->attr_name;
687688
dev->attr.attr.mode = 0444;
@@ -690,7 +691,8 @@ int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
690691
if (result)
691692
goto remove_symbol_link;
692693

693-
sprintf(dev->weight_attr_name, "cdev%d_weight", dev->id);
694+
snprintf(dev->weight_attr_name, sizeof(dev->weight_attr_name),
695+
"cdev%d_weight", dev->id);
694696
sysfs_attr_init(&dev->weight_attr.attr);
695697
dev->weight_attr.attr.name = dev->weight_attr_name;
696698
dev->weight_attr.attr.mode = S_IWUSR | S_IRUGO;

0 commit comments

Comments
 (0)