Skip to content

Commit 62a1a58

Browse files
tiwaiJiri Kosina
authored andcommitted
HID: hid-sensor-custom: 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: Jiri Kosina <[email protected]>
1 parent 42f502d commit 62a1a58

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/hid/hid-sensor-custom.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr,
313313

314314
while (i < ret) {
315315
if (i + attribute->size > ret) {
316-
len += snprintf(&buf[len],
316+
len += scnprintf(&buf[len],
317317
PAGE_SIZE - len,
318318
"%d ", values[i]);
319319
break;
@@ -336,10 +336,10 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr,
336336
++i;
337337
break;
338338
}
339-
len += snprintf(&buf[len], PAGE_SIZE - len,
339+
len += scnprintf(&buf[len], PAGE_SIZE - len,
340340
"%lld ", value);
341341
}
342-
len += snprintf(&buf[len], PAGE_SIZE - len, "\n");
342+
len += scnprintf(&buf[len], PAGE_SIZE - len, "\n");
343343

344344
return len;
345345
} else if (input)

0 commit comments

Comments
 (0)