Skip to content

Commit 949fe25

Browse files
tiwairafaeljw
authored andcommitted
ACPI: fan: 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(). Also adjust the argument to really match with the actually remaining buffer size. Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 2c523b3 commit 949fe25

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/acpi/fan.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,29 +276,29 @@ static ssize_t show_state(struct device *dev, struct device_attribute *attr, cha
276276
int count;
277277

278278
if (fps->control == 0xFFFFFFFF || fps->control > 100)
279-
count = snprintf(buf, PAGE_SIZE, "not-defined:");
279+
count = scnprintf(buf, PAGE_SIZE, "not-defined:");
280280
else
281-
count = snprintf(buf, PAGE_SIZE, "%lld:", fps->control);
281+
count = scnprintf(buf, PAGE_SIZE, "%lld:", fps->control);
282282

283283
if (fps->trip_point == 0xFFFFFFFF || fps->trip_point > 9)
284-
count += snprintf(&buf[count], PAGE_SIZE, "not-defined:");
284+
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
285285
else
286-
count += snprintf(&buf[count], PAGE_SIZE, "%lld:", fps->trip_point);
286+
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->trip_point);
287287

288288
if (fps->speed == 0xFFFFFFFF)
289-
count += snprintf(&buf[count], PAGE_SIZE, "not-defined:");
289+
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
290290
else
291-
count += snprintf(&buf[count], PAGE_SIZE, "%lld:", fps->speed);
291+
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->speed);
292292

293293
if (fps->noise_level == 0xFFFFFFFF)
294-
count += snprintf(&buf[count], PAGE_SIZE, "not-defined:");
294+
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
295295
else
296-
count += snprintf(&buf[count], PAGE_SIZE, "%lld:", fps->noise_level * 100);
296+
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->noise_level * 100);
297297

298298
if (fps->power == 0xFFFFFFFF)
299-
count += snprintf(&buf[count], PAGE_SIZE, "not-defined\n");
299+
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined\n");
300300
else
301-
count += snprintf(&buf[count], PAGE_SIZE, "%lld\n", fps->power);
301+
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld\n", fps->power);
302302

303303
return count;
304304
}

0 commit comments

Comments
 (0)