From f2affbd973a72f094f7d8e4b72829dc2f0e768ed Mon Sep 17 00:00:00 2001 From: Rico Ganahl Date: Mon, 28 Mar 2022 13:07:48 +0200 Subject: [PATCH] os: lib: bin2hex: fix memory overwrite Destination buffer size could be too small by one, but null termination is still written. This could cause an overwrite in contiguous memory without notice. Signed-off-by: Rico Ganahl --- lib/os/hex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/os/hex.c b/lib/os/hex.c index 6472bc96930..478dded506c 100644 --- a/lib/os/hex.c +++ b/lib/os/hex.c @@ -39,7 +39,7 @@ int hex2char(uint8_t x, char *c) size_t bin2hex(const uint8_t *buf, size_t buflen, char *hex, size_t hexlen) { - if ((hexlen + 1) < buflen * 2) { + if (hexlen < (buflen * 2 + 1)) { return 0; }