]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
lib/hexdump.c: truncate output in case of overflow
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Sat, 7 Nov 2015 00:31:31 +0000 (16:31 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 19 Feb 2016 22:28:24 +0000 (14:28 -0800)
commit2343eaa317134614f5dfc25e63c8f2088fd3b5f5
tree64529933f9f0acb64fd785db6099fa815daaa9f9
parent83d79c0d3a568141b7792d999daf8f28e2d6c9fb
lib/hexdump.c: truncate output in case of overflow

commit 9f029f540c2f7e010e4922d44ba0dfd05da79f88 upstream.

There is a classical off-by-one error in case when we try to place, for
example, 1+1 bytes as hex in the buffer of size 6.  The expected result is
to get an output truncated, but in the reality we get 6 bytes filed
followed by terminating NUL.

Change the logic how we fill the output in case of byte dumping into
limited space.  This will follow the snprintf() behaviour by truncating
output even on half bytes.

Fixes: 114fc1afb2de (hexdump: make it return number of bytes placed in buffer)
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reported-by: Aaro Koskinen <aaro.koskinen@nokia.com>
Tested-by: Aaro Koskinen <aaro.koskinen@nokia.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lib/hexdump.c