All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hex2bin: fix access beyond string end
@ 2022-04-24 20:48 ` Mikulas Patocka
  0 siblings, 0 replies; 20+ messages in thread
From: Mikulas Patocka @ 2022-04-24 20:48 UTC (permalink / raw)
  To: Linus Torvalds, Andy Shevchenko, Mimi Zohar
  Cc: dm-devel, linux-kernel, Mike Snitzer, Milan Broz

If we pass too short string to "hex2bin" (and the string size without the
terminating NUL character is even), "hex2bin" reads one byte after the
terminating NUL character. This patch fixes it.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org

---
 lib/hexdump.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Index: linux-2.6/lib/hexdump.c
===================================================================
--- linux-2.6.orig/lib/hexdump.c	2022-04-24 18:51:16.000000000 +0200
+++ linux-2.6/lib/hexdump.c	2022-04-24 18:51:16.000000000 +0200
@@ -45,10 +45,13 @@ EXPORT_SYMBOL(hex_to_bin);
 int hex2bin(u8 *dst, const char *src, size_t count)
 {
 	while (count--) {
-		int hi = hex_to_bin(*src++);
-		int lo = hex_to_bin(*src++);
+		int hi, lo;
 
-		if ((hi < 0) || (lo < 0))
+		hi = hex_to_bin(*src++);
+		if (hi < 0)
+			return -EINVAL;
+		lo = hex_to_bin(*src++);
+		if (lo < 0)
 			return -EINVAL;
 
 		*dst++ = (hi << 4) | lo;


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-04-29  8:24 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-24 20:48 [PATCH] hex2bin: fix access beyond string end Mikulas Patocka
2022-04-24 20:48 ` [dm-devel] " Mikulas Patocka
2022-04-26 10:37 ` Andy Shevchenko
2022-04-26 10:37   ` [dm-devel] " Andy Shevchenko
2022-04-26 12:07   ` [PATCH v2] " Mikulas Patocka
2022-04-26 12:07     ` [dm-devel] " Mikulas Patocka
2022-04-26 13:18     ` Andy Shevchenko
2022-04-26 13:18       ` [dm-devel] " Andy Shevchenko
2022-04-26 13:19     ` Andy Shevchenko
2022-04-26 13:19       ` [dm-devel] " Andy Shevchenko
2022-04-26 15:29       ` Mikulas Patocka
2022-04-26 15:29         ` [dm-devel] " Mikulas Patocka
2022-04-27 12:24         ` Andy Shevchenko
2022-04-27 12:24           ` [dm-devel] " Andy Shevchenko
2022-04-27 14:10           ` Mikulas Patocka
2022-04-27 14:10             ` [dm-devel] " Mikulas Patocka
2022-04-27 14:49             ` Andy Shevchenko
2022-04-27 14:49               ` [dm-devel] " Andy Shevchenko
2022-04-27 15:26               ` [PATCH v3] " Mikulas Patocka
2022-04-27 15:26                 ` [dm-devel] " Mikulas Patocka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.