]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Core: Add support for hex encoded characters in printf
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 Jan 2019 13:03:24 +0000 (13:03 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 Jan 2019 13:03:24 +0000 (13:03 +0000)
src/libutil/printf.c

index 148b49d9ed9e48062770dde02730c0d30cb667c1..476c4de40c0c9a41c641a4f6b1eacf33b7025cd1 100644 (file)
@@ -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;