Browse Source

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 <rico.ganahl@bytesatwork.ch>
pull/44859/head
Rico Ganahl 3 years ago committed by Marti Bolivar
parent
commit
f2affbd973
  1. 2
      lib/os/hex.c

2
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) 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; return 0;
} }

Loading…
Cancel
Save