Skip to content

Commit 4636a04

Browse files
tiwaigregkh
authored andcommitted
drivers/base/cpu: 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]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9a2dd57 commit 4636a04

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/base/cpu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ static ssize_t print_cpus_offline(struct device *dev,
258258
buf[n++] = ',';
259259

260260
if (nr_cpu_ids == total_cpus-1)
261-
n += snprintf(&buf[n], len - n, "%u", nr_cpu_ids);
261+
n += scnprintf(&buf[n], len - n, "%u", nr_cpu_ids);
262262
else
263-
n += snprintf(&buf[n], len - n, "%u-%d",
263+
n += scnprintf(&buf[n], len - n, "%u-%d",
264264
nr_cpu_ids, total_cpus-1);
265265
}
266266

267-
n += snprintf(&buf[n], len - n, "\n");
267+
n += scnprintf(&buf[n], len - n, "\n");
268268
return n;
269269
}
270270
static DEVICE_ATTR(offline, 0444, print_cpus_offline, NULL);

0 commit comments

Comments
 (0)