diff options
author | Bruno Prémont <bonbons@linux-vserver.org> | 2012-09-19 15:18:10 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2012-09-24 17:04:55 -0400 |
commit | 5ed84c341c25accc61410cfb53a45170f8fb19e4 (patch) | |
tree | ba7df0b10aafff90cdcedf8307803c0da8e25339 /drivers/hid/hid-picolcd_debugfs.c | |
parent | 206e3f1cda4d6113bdbb3656917d481b9ad447e4 (diff) |
HID: picoLCD: bounds check in dump_buff_as_hex()
Make sure we keep enough space for terminating NUL character after last
newline. If we have too much data, replace last byte with '.'s to
make overflow visible.
Using hex_dump_to_buffer() is not interesting as it adds more overhead
and does not append the trailing linefeed.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Bruno Prémont <bonbons@linux-vserver.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-picolcd_debugfs.c')
-rw-r--r-- | drivers/hid/hid-picolcd_debugfs.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/hid/hid-picolcd_debugfs.c b/drivers/hid/hid-picolcd_debugfs.c index eec85b53bb2c..6ef03be352cf 100644 --- a/drivers/hid/hid-picolcd_debugfs.c +++ b/drivers/hid/hid-picolcd_debugfs.c | |||
@@ -381,16 +381,16 @@ static void dump_buff_as_hex(char *dst, size_t dst_sz, const u8 *data, | |||
381 | const size_t data_len) | 381 | const size_t data_len) |
382 | { | 382 | { |
383 | int i, j; | 383 | int i, j; |
384 | for (i = j = 0; i < data_len && j + 3 < dst_sz; i++) { | 384 | for (i = j = 0; i < data_len && j + 4 < dst_sz; i++) { |
385 | dst[j++] = hex_asc[(data[i] >> 4) & 0x0f]; | 385 | dst[j++] = hex_asc[(data[i] >> 4) & 0x0f]; |
386 | dst[j++] = hex_asc[data[i] & 0x0f]; | 386 | dst[j++] = hex_asc[data[i] & 0x0f]; |
387 | dst[j++] = ' '; | 387 | dst[j++] = ' '; |
388 | } | 388 | } |
389 | if (j < dst_sz) { | 389 | dst[j] = '\0'; |
390 | dst[j--] = '\0'; | 390 | if (j > 0) |
391 | dst[j] = '\n'; | 391 | dst[j-1] = '\n'; |
392 | } else | 392 | if (i < data_len && j > 2) |
393 | dst[j] = '\0'; | 393 | dst[j-2] = dst[j-3] = '.'; |
394 | } | 394 | } |
395 | 395 | ||
396 | void picolcd_debug_out_report(struct picolcd_data *data, | 396 | void picolcd_debug_out_report(struct picolcd_data *data, |