Commit 6a096871 authored by Takashi Iwai's avatar Takashi Iwai Committed by Guenter Roeck

hwmon: (ibmpowernv) Use scnprintf() for avoiding potential buffer overflow

Since snprintf() returns the would-be-output size instead of the
actual output size, the succeeding calls may go beyond the given
buffer limit.  Fix it by replacing with scnprintf().
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 86da28ee
...@@ -186,7 +186,7 @@ static void make_sensor_label(struct device_node *np, ...@@ -186,7 +186,7 @@ static void make_sensor_label(struct device_node *np,
u32 id; u32 id;
size_t n; size_t n;
n = snprintf(sdata->label, sizeof(sdata->label), "%s", label); n = scnprintf(sdata->label, sizeof(sdata->label), "%s", label);
/* /*
* Core temp pretty print * Core temp pretty print
...@@ -199,11 +199,11 @@ static void make_sensor_label(struct device_node *np, ...@@ -199,11 +199,11 @@ static void make_sensor_label(struct device_node *np,
* The digital thermal sensors are associated * The digital thermal sensors are associated
* with a core. * with a core.
*/ */
n += snprintf(sdata->label + n, n += scnprintf(sdata->label + n,
sizeof(sdata->label) - n, " %d", sizeof(sdata->label) - n, " %d",
cpuid); cpuid);
else else
n += snprintf(sdata->label + n, n += scnprintf(sdata->label + n,
sizeof(sdata->label) - n, " phy%d", id); sizeof(sdata->label) - n, " phy%d", id);
} }
...@@ -211,7 +211,7 @@ static void make_sensor_label(struct device_node *np, ...@@ -211,7 +211,7 @@ static void make_sensor_label(struct device_node *np,
* Membuffer pretty print * Membuffer pretty print
*/ */
if (!of_property_read_u32(np, "ibm,chip-id", &id)) if (!of_property_read_u32(np, "ibm,chip-id", &id))
n += snprintf(sdata->label + n, sizeof(sdata->label) - n, n += scnprintf(sdata->label + n, sizeof(sdata->label) - n,
" %d", id & 0xffff); " %d", id & 0xffff);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment