From: Guenter Roeck Date: Sat, 21 Jul 2012 00:53:48 +0000 (+1000) Subject: thermal: fix potential out-of-bounds memory access X-Git-Tag: next-20120816~63^2~2 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=372f46d78a129553d34a9f53bc2ed8ae5cdac915;p=karo-tx-linux.git thermal: fix potential out-of-bounds memory access temp_crit.name and temp_input.name have a length of 16 bytes. Using THERMAL_NAME_LENGTH (20) as length parameter for snprintf() may result in out-of-bounds memory accesses. Replace it with sizeof(). Addresses Coverity #115679 Signed-off-by: Zhang Rui Signed-off-by: Guenter Roeck Cc: Len Brown Cc: "Brown, Len" Signed-off-by: Andrew Morton --- diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c index 5be8728c88a3..36e6f4d4ec3b 100644 --- a/drivers/thermal/thermal_sys.c +++ b/drivers/thermal/thermal_sys.c @@ -598,7 +598,7 @@ thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) temp->tz = tz; hwmon->count++; - snprintf(temp->temp_input.name, THERMAL_NAME_LENGTH, + snprintf(temp->temp_input.name, sizeof(temp->temp_input.name), "temp%d_input", hwmon->count); temp->temp_input.attr.attr.name = temp->temp_input.name; temp->temp_input.attr.attr.mode = 0444; @@ -611,7 +611,8 @@ thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) if (tz->ops->get_crit_temp) { unsigned long temperature; if (!tz->ops->get_crit_temp(tz, &temperature)) { - snprintf(temp->temp_crit.name, THERMAL_NAME_LENGTH, + snprintf(temp->temp_crit.name, + sizeof(temp->temp_crit.name), "temp%d_crit", hwmon->count); temp->temp_crit.attr.attr.name = temp->temp_crit.name; temp->temp_crit.attr.attr.mode = 0444;