[syslog-ng] problem with accents in log messages

Balazs Scheidler bazsi at balabit.hu
Thu Apr 5 13:25:19 CEST 2007


On Thu, 2007-04-05 at 11:47 +0200, Nagy Daniel wrote:
> Hello,
> 
> Got it, template_escape(no) solves the problem.
> 

This is a genuine bug nevertheless. The patch below should fix it (in
fact the single gchar->guchar change is the fix, the rest is just
cosmetics and a testcase update to cover this case):

--- orig/src/macros.c
+++ mod/src/macros.c
@@ -111,7 +111,7 @@ macros[] =
 GHashTable *macro_hash;
 
 static void
-result_append(GString *result, gchar *str, gint len, gboolean escape)
+result_append(GString *result, guchar *str, gsize len, gboolean escape)
 {
   gint i;
   
@@ -126,7 +126,7 @@ result_append(GString *result, gchar *st
             }
           else if (str[i] < ' ')
             {
-              g_string_sprintfa(result, "\\%03o", (unsigned int) str[i]);
+              g_string_sprintfa(result, "\\%03o", str[i]);
             }
           else
             g_string_append_c(result, str[i]);


--- orig/tests/unit/test_template.c
+++ mod/tests/unit/test_template.c
@@ -2,6 +2,7 @@
 #include "logmsg.h"
 #include "templates.h"
 #include "misc.h"
+#include "macros.h"
 
 #include <time.h>
 #include <stdlib.h>
@@ -16,7 +17,7 @@ testcase(LogMessage *msg, gchar *templat
   GString *res = g_string_sized_new(128);
   
   templ = log_template_new("dummy", template);
-  log_template_format(templ, msg, 0, TS_FMT_BSD, -1, 3, res);
+  log_template_format(templ, msg, MF_ESCAPE_RESULT, TS_FMT_BSD, -1, 3, res);
   
   if (strcmp(res->str, expected) != 0)
     {
@@ -35,7 +36,7 @@ int 
 main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
 {
   LogMessage *msg;
-  char *msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]: test message";
+  char *msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]: árvíztűrőtükörfúrógép";
   
   putenv("TZ=CET");
   tzset();
@@ -108,9 +109,9 @@ main(int argc G_GNUC_UNUSED, char *argv[
   testcase(msg, "$FULLHOST", "bzorp");
   testcase(msg, "$PROGRAM", "syslog-ng");
   testcase(msg, "$PID", "23323");
-  testcase(msg, "$MSG", "syslog-ng[23323]: test message");
-  testcase(msg, "$MSGONLY", "test message");
-  testcase(msg, "$MESSAGE", "syslog-ng[23323]: test message");
+  testcase(msg, "$MSG", "syslog-ng[23323]: árvíztűrőtükörfúrógép");
+  testcase(msg, "$MSGONLY", "árvíztűrőtükörfúrógép");
+  testcase(msg, "$MESSAGE", "syslog-ng[23323]: árvíztűrőtükörfúrógép");
   testcase(msg, "$SOURCEIP", "10.10.10.10");
   testcase(msg, "$PROGRAM/var/log/messages/$HOST/$HOST_FROM/$MONTH$DAY$QQQQQvalami", "syslog-ng/var/log/messages/bzorp/kismacska/0211valami");
   if (success)




-- 
Bazsi



More information about the syslog-ng mailing list