From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Aaro Koskinen <aaro.koskinen@nokia.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Catalin Marinas <catalin.marinas@arm.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [RFT, PATCH v1 1/1] hexdump: truncate output in case of overflow
Date: Wed, 28 Oct 2015 12:48:19 +0200 [thread overview]
Message-ID: <1446029299-34523-1-git-send-email-andriy.shevchenko@linux.intel.com> (raw)
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)
Reported-by: Aaro Koskinen <aaro.koskinen@nokia.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
Waiting for Aaro's Tested-by: tag, that's why RFT. Meanwhile I will update
test-hexdump to cover all corner case in overflow.
Linus, it would be nice to promote the fix when we get Aaro's confirmation.
lib/hexdump.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 8d74c20..992457b 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -169,11 +169,15 @@ int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize,
}
} else {
for (j = 0; j < len; j++) {
- if (linebuflen < lx + 3)
+ if (linebuflen < lx + 2)
goto overflow2;
ch = ptr[j];
linebuf[lx++] = hex_asc_hi(ch);
+ if (linebuflen < lx + 2)
+ goto overflow2;
linebuf[lx++] = hex_asc_lo(ch);
+ if (linebuflen < lx + 2)
+ goto overflow2;
linebuf[lx++] = ' ';
}
if (j)
--
2.6.1
next reply other threads:[~2015-10-28 10:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-28 10:48 Andy Shevchenko [this message]
2015-10-28 13:24 ` Aaro Koskinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1446029299-34523-1-git-send-email-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=aaro.koskinen@nokia.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome