commit f8d6761: [Minor] Core: Add support for hex encoded characters in printf

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Jan 11 15:35:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-01-11 13:03:24 +0000
URL: https://github.com/rspamd/rspamd/commit/f8d6761a366a3d884c85410ec356d4c4927a8697

[Minor] Core: Add support for hex encoded characters in printf

---
 src/libutil/printf.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index 148b49d9e..476c4de40 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -979,7 +979,17 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
 			case 'c':
 				c = va_arg (args, gint);
 				c &= 0xff;
-				RSPAMD_PRINTF_APPEND (&c, 1);
+				if (G_UNLIKELY (hex)) {
+					gchar hexbuf[2];
+					hexbuf[0] = hex == 2 ? _HEX[(c >> 4) & 0xf] :
+								_hex[(c >> 4) & 0xf];
+					hexbuf[1] = hex == 2 ? _HEX[c & 0xf] : _hex[c & 0xf];
+
+					RSPAMD_PRINTF_APPEND (hexbuf, 2);
+				}
+				else {
+					RSPAMD_PRINTF_APPEND (&c, 1);
+				}
 
 				continue;
 


More information about the Commits mailing list