util: fix UTI_BytesToHex() to handle zero-length input

This commit is contained in:
Miroslav Lichvar
2020-09-30 14:07:04 +02:00
parent a655eab34f
commit 944cf6e318
2 changed files with 8 additions and 0 deletions

5
util.c
View File

@@ -1417,6 +1417,11 @@ UTI_BytesToHex(const void *buf, unsigned int buf_len, char *hex, unsigned int he
{
unsigned int i, l;
if (hex_len < 1)
return 0;
hex[0] = '\0';
for (i = l = 0; i < buf_len; i++, l += 2) {
if (l + 2 >= hex_len ||
snprintf(hex + l, hex_len - l, "%02hhX", ((const char *)buf)[i]) != 2)