Skip to content

Commit 6a09687

Browse files
tiwaigroeck
authored andcommitted
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: Takashi Iwai <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 86da28e commit 6a09687

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/hwmon/ibmpowernv.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static void make_sensor_label(struct device_node *np,
186186
u32 id;
187187
size_t n;
188188

189-
n = snprintf(sdata->label, sizeof(sdata->label), "%s", label);
189+
n = scnprintf(sdata->label, sizeof(sdata->label), "%s", label);
190190

191191
/*
192192
* Core temp pretty print
@@ -199,19 +199,19 @@ static void make_sensor_label(struct device_node *np,
199199
* The digital thermal sensors are associated
200200
* with a core.
201201
*/
202-
n += snprintf(sdata->label + n,
202+
n += scnprintf(sdata->label + n,
203203
sizeof(sdata->label) - n, " %d",
204204
cpuid);
205205
else
206-
n += snprintf(sdata->label + n,
206+
n += scnprintf(sdata->label + n,
207207
sizeof(sdata->label) - n, " phy%d", id);
208208
}
209209

210210
/*
211211
* Membuffer pretty print
212212
*/
213213
if (!of_property_read_u32(np, "ibm,chip-id", &id))
214-
n += snprintf(sdata->label + n, sizeof(sdata->label) - n,
214+
n += scnprintf(sdata->label + n, sizeof(sdata->label) - n,
215215
" %d", id & 0xffff);
216216
}
217217

0 commit comments

Comments
 (0)