1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

lib:util: Fix printing hex‐escaped characters

A signed char, passed to snprintf(), will be promoted to an ‘int’, and
then interpreted (according to the format string) as an ‘unsigned int’.
Any negative values passed in will thus be interpreted as large unsigned
values, too large to be represented in the two characters allocated for
them. In practice, they will always be represented as ‘\xFF’.

Cast these characters to ‘unsigned char’, and use the appropriate length
modifier for that type.

Signed-off-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Jo Sutton 2024-02-20 16:35:43 +13:00 committed by Andrew Bartlett
parent 7e855f8d89
commit 3b85345c4c

View File

@ -116,7 +116,7 @@ char *log_escape(TALLOC_CTX *frame, const char *in)
*e++ = '\\';
break;
default:
snprintf(e, 5, "\\x%02X", *c);
snprintf(e, 5, "\\x%02hhX", (unsigned char)(*c));
e += 4;
}
c++;