]> git.baikalelectronics.ru Git - kernel.git/commit
hex2bin: fix access beyond string end
authorMikulas Patocka <mpatocka@redhat.com>
Wed, 27 Apr 2022 15:26:40 +0000 (11:26 -0400)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 27 Apr 2022 17:57:33 +0000 (10:57 -0700)
commit64d6e3ae2c2acb89be32685a0d9c3c8ada5094e4
treef00d3677b90779d9ff1a41bb401e8c9f40c69d1c
parent7084936c7c5fdbd24b4a9cc58da2b423e050608a
hex2bin: fix access beyond string end

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.

Note that hex_to_bin returns -1 on error and hex2bin return -EINVAL on
error - so we can't just return the variable "hi" or "lo" on error.
This inconsistency may be fixed in the next merge window, but for the
purpose of fixing this bug, we just preserve the existing behavior and
return -1 and -EINVAL.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Fixes: 4ea57775e6ee ("lib: add error checking to hex2bin")
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/hexdump.c