[syslog-ng] [PATCH] patterndb: Fix test_patterndb crash when testing outside-of-rule db lookups.

Nick Alcock nix at esperi.org.uk
Fri Apr 4 12:29:03 CEST 2014


First test_patterndb_tags_outside_of_rule() nulls out the messages pointer,
then it calls clean_pattern_db(), which unconditionally dereferences it.

This will never work.

Guard the use of messages in clean_pattern_db() with a nullity check.

Signed-off-by: Nick Alcock <nix at esperi.org.uk>
---
 modules/dbparser/tests/test_patterndb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/modules/dbparser/tests/test_patterndb.c b/modules/dbparser/tests/test_patterndb.c
index 7ad7f09..ea7c576 100644
--- a/modules/dbparser/tests/test_patterndb.c
+++ b/modules/dbparser/tests/test_patterndb.c
@@ -69,8 +69,11 @@ create_pattern_db(gchar *pdb)
 void
 clean_pattern_db(void)
 {
-  g_ptr_array_foreach(messages, (GFunc) log_msg_unref, NULL);
-  g_ptr_array_free(messages, TRUE);
+  if (messages)
+    {
+      g_ptr_array_foreach(messages, (GFunc) log_msg_unref, NULL);
+      g_ptr_array_free(messages, TRUE);
+    }
   pattern_db_free(patterndb);
   patterndb = NULL;
 
-- 
1.9.1.171.gc28c581


More information about the syslog-ng mailing list