[syslog-ng] [PATCH (3.4) 1/4] jsonparser: Handle invalid JSON input properly.

Gergely Nagy algernon at balabit.hu
Tue Jan 10 13:11:06 CET 2012


When JSON parsing fails, handle it gracefully, by printing an error
message and returning immediately, instead of ending up segfaulting.

Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
 modules/jsonparser/jsonparser.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/modules/jsonparser/jsonparser.c b/modules/jsonparser/jsonparser.c
index 9347a5c..74e83a8 100644
--- a/modules/jsonparser/jsonparser.c
+++ b/modules/jsonparser/jsonparser.c
@@ -57,6 +57,12 @@ log_json_parser_process (LogParser *s, LogMessage *msg, const gchar *input)
   key = scratch_buffer_acquire ();
   value = scratch_buffer_acquire ();
 
+  if (!jso)
+    {
+      msg_error ("Unparsable JSON stream encountered", NULL);
+      return FALSE;
+    }
+
   json_object_object_foreachC (jso, itr)
     {
       gboolean parsed = FALSE;
-- 
1.7.7.3




More information about the syslog-ng mailing list