[Forensics-changes] [yara] 218/368: tests: Output compile errors

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:30:41 UTC 2017


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag v3.5.0
in repository yara.

commit 486780634200ccee8b79dbb49336158fab498a2c
Author: Hilko Bengen <bengen at hilluzination.de>
Date:   Tue Mar 1 22:10:57 2016 +0100

    tests: Output compile errors
---
 tests/util.c | 20 ++++++++++++++++++--
 tests/util.h |  5 +++--
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/tests/util.c b/tests/util.c
index 1a2e69a..32af34d 100644
--- a/tests/util.c
+++ b/tests/util.c
@@ -19,6 +19,18 @@ limitations under the License.
 
 #include <yara.h>
 
+char compile_error[1024];
+
+static void callback_function(
+    int error_level,
+    const char* file_name,
+    int line_number,
+    const char* message,
+    void* user_data)
+{
+  snprintf(compile_error, sizeof(compile_error), "line %d: %s", line_number, message);
+}
+
 
 YR_RULES* compile_rule(
     char* string)
@@ -26,12 +38,16 @@ YR_RULES* compile_rule(
   YR_COMPILER* compiler = NULL;
   YR_RULES* rules = NULL;
 
+  compile_error[0] = '\0';
+
   if (yr_compiler_create(&compiler) != ERROR_SUCCESS)
   {
     perror("yr_compiler_create");
     goto _exit;
   }
 
+  yr_compiler_set_callback(compiler, callback_function, NULL);
+
   if (yr_compiler_add_string(compiler, string, NULL) != 0)
   {
     goto _exit;
@@ -77,7 +93,7 @@ int matches_blob(
 
   if (rules == NULL)
   {
-    fprintf(stderr, "failed to compile rule << %s >>\n", rule);
+    fprintf(stderr, "failed to compile rule << %s >>: %s\n", rule, compile_error);
     exit(EXIT_FAILURE);
   }
 
@@ -154,7 +170,7 @@ int capture_string(
 
   if (rules == NULL)
   {
-    fprintf(stderr, "failed to compile rule << %s >>\n", rule);
+    fprintf(stderr, "failed to compile rule << %s >>: %s\n", rule, compile_error);
     exit(EXIT_FAILURE);
   }
 
diff --git a/tests/util.h b/tests/util.h
index 0e4c67a..8a86937 100644
--- a/tests/util.h
+++ b/tests/util.h
@@ -17,6 +17,7 @@ limitations under the License.
 #ifndef _UTIL_H
 #define _UTIL_H
 
+extern char compile_error[1024];
 
 YR_RULES* compile_rule(
     char* string);
@@ -77,8 +78,8 @@ int capture_string(
 
 #define assert_syntax_correct(rule) do {                                \
     if (compile_rule(rule) == NULL) {                                   \
-      fprintf(stderr, "%s:%d: rule can't be compiled (but should)\n",   \
-              __FILE__, __LINE__);                                      \
+      fprintf(stderr, "%s:%d: rule << %s >> can't be compiled: %s\n",   \
+              __FILE__, __LINE__, rule, compile_error);                 \
       exit(EXIT_FAILURE);                                               \
     }                                                                   \
   } while(0);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/yara.git



More information about the forensics-changes mailing list