[Forensics-changes] [yara] 157/368: Fix issue #369.

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:30:23 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 f867aee70cf52e1ea70ee7b4c2deee09a6cb10b8
Author: Victor M. Alvarez <plusvic at gmail.com>
Date:   Fri Jan 22 20:51:32 2016 +0100

    Fix issue #369.
    
    An error is returned when string identifiers are duplicated within a rule.
---
 libyara/compiler.c              |   7 +
 libyara/grammar.c               | 863 ++++++++++++++++++++--------------------
 libyara/grammar.y               |  14 +-
 libyara/hash.c                  |  12 +-
 libyara/include/yara/compiler.h |   1 +
 libyara/include/yara/hash.h     |   5 +
 libyara/include/yara/parser.h   |   5 +-
 libyara/lexer.c                 |   2 +-
 libyara/parser.c                |  39 +-
 9 files changed, 504 insertions(+), 444 deletions(-)

diff --git a/libyara/compiler.c b/libyara/compiler.c
index 4ec6358..5294430 100644
--- a/libyara/compiler.c
+++ b/libyara/compiler.c
@@ -62,6 +62,9 @@ YR_API int yr_compiler_create(
     result = yr_hash_table_create(10007, &new_compiler->objects_table);
 
   if (result == ERROR_SUCCESS)
+    result = yr_hash_table_create(101, &new_compiler->strings_table);
+
+  if (result == ERROR_SUCCESS)
     result = yr_arena_create(65536, 0, &new_compiler->sz_arena);
 
   if (result == ERROR_SUCCESS)
@@ -128,6 +131,10 @@ YR_API void yr_compiler_destroy(
       NULL);
 
   yr_hash_table_destroy(
+      compiler->strings_table,
+      NULL);
+
+  yr_hash_table_destroy(
       compiler->objects_table,
       (YR_HASH_TABLE_FREE_VALUE_FUNC) yr_object_destroy);
 
diff --git a/libyara/grammar.c b/libyara/grammar.c
index c76ee63..63db701 100644
--- a/libyara/grammar.c
+++ b/libyara/grammar.c
@@ -512,11 +512,11 @@ union yyalloc
 /* YYNTOKENS -- Number of terminals.  */
 #define YYNTOKENS  72
 /* YYNNTS -- Number of nonterminals.  */
-#define YYNNTS  39
+#define YYNNTS  40
 /* YYNRULES -- Number of rules.  */
-#define YYNRULES  118
+#define YYNRULES  119
 /* YYNRULES -- Number of states.  */
-#define YYNSTATES  205
+#define YYNSTATES  206
 
 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
 #define YYUNDEFTOK  2
@@ -567,17 +567,17 @@ static const yytype_uint8 yytranslate[] =
 static const yytype_uint16 yyprhs[] =
 {
        0,     0,     3,     4,     7,    10,    14,    18,    22,    25,
-      26,    37,    38,    42,    43,    47,    51,    52,    55,    57,
-      59,    60,    63,    65,    68,    70,    73,    77,    81,    85,
-      89,    91,    94,    99,   100,   106,   110,   111,   114,   116,
-     118,   120,   122,   124,   128,   133,   138,   139,   141,   143,
-     147,   149,   151,   153,   155,   159,   163,   165,   169,   173,
-     174,   175,   187,   188,   198,   202,   205,   206,   211,   212,
-     217,   221,   225,   229,   233,   237,   241,   243,   247,   251,
-     253,   259,   261,   265,   266,   271,   273,   275,   279,   281,
-     283,   285,   287,   289,   293,   295,   297,   302,   304,   306,
-     308,   310,   315,   317,   322,   324,   326,   329,   333,   337,
-     341,   345,   349,   353,   357,   361,   364,   368,   372
+      26,    27,    39,    40,    44,    45,    49,    53,    54,    57,
+      59,    61,    62,    65,    67,    70,    72,    75,    79,    83,
+      87,    91,    93,    96,   101,   102,   108,   112,   113,   116,
+     118,   120,   122,   124,   126,   130,   135,   140,   141,   143,
+     145,   149,   151,   153,   155,   157,   161,   165,   167,   171,
+     175,   176,   177,   189,   190,   200,   204,   207,   208,   213,
+     214,   219,   223,   227,   231,   235,   239,   243,   245,   249,
+     253,   255,   261,   263,   267,   268,   273,   275,   277,   281,
+     283,   285,   287,   289,   291,   295,   297,   299,   304,   306,
+     308,   310,   312,   317,   319,   324,   326,   328,   331,   335,
+     339,   343,   347,   351,   355,   359,   363,   366,   370,   374
 };
 
 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
@@ -585,59 +585,59 @@ static const yytype_int8 yyrhs[] =
 {
       73,     0,    -1,    -1,    73,    75,    -1,    73,    74,    -1,
       73,     1,    75,    -1,    73,     1,    74,    -1,    73,     1,
-      61,    -1,    37,    19,    -1,    -1,    80,     4,    10,    82,
-      62,    77,    78,    76,    79,    63,    -1,    -1,     7,    64,
-      84,    -1,    -1,     8,    64,    86,    -1,     9,    64,    95,
-      -1,    -1,    80,    81,    -1,     5,    -1,     6,    -1,    -1,
-      64,    83,    -1,    10,    -1,    83,    10,    -1,    85,    -1,
-      84,    85,    -1,    10,    65,    19,    -1,    10,    65,    16,
-      -1,    10,    65,    38,    -1,    10,    65,    39,    -1,    87,
-      -1,    86,    87,    -1,    11,    65,    19,    89,    -1,    -1,
-      11,    65,    88,    21,    89,    -1,    11,    65,    20,    -1,
-      -1,    89,    90,    -1,    23,    -1,    22,    -1,    24,    -1,
-      25,    -1,    10,    -1,    91,    66,    10,    -1,    91,    67,
-     110,    68,    -1,    91,    69,    92,    70,    -1,    -1,    93,
-      -1,    96,    -1,    93,    71,    96,    -1,    21,    -1,    96,
-      -1,    38,    -1,    39,    -1,   110,    35,    94,    -1,   110,
-      36,   110,    -1,    11,    -1,    11,    26,   110,    -1,    11,
-      31,   103,    -1,    -1,    -1,    33,   109,    10,    31,    97,
-     102,    64,    98,    69,    95,    70,    -1,    -1,    33,   109,
-      32,   105,    64,    99,    69,    95,    70,    -1,   109,    32,
-     105,    -1,    60,    95,    -1,    -1,    95,    41,   100,    95,
-      -1,    -1,    95,    40,   101,    95,    -1,   110,    50,   110,
-      -1,   110,    48,   110,    -1,   110,    49,   110,    -1,   110,
-      47,   110,    -1,   110,    46,   110,    -1,   110,    45,   110,
-      -1,   110,    -1,    69,    96,    70,    -1,    69,   104,    70,
-      -1,   103,    -1,    69,   110,     3,   110,    70,    -1,   110,
-      -1,   104,    71,   110,    -1,    -1,    69,   106,   107,    70,
-      -1,    34,    -1,   108,    -1,   107,    71,   108,    -1,    11,
-      -1,    15,    -1,   110,    -1,    29,    -1,    30,    -1,    69,
-     110,    70,    -1,    27,    -1,    28,    -1,    18,    69,   110,
-      70,    -1,    16,    -1,    17,    -1,    19,    -1,    12,    -1,
-      13,    67,   110,    68,    -1,    13,    -1,    14,    67,   110,
-      68,    -1,    14,    -1,    91,    -1,    54,   110,    -1,   110,
-      53,   110,    -1,   110,    54,   110,    -1,   110,    55,   110,
-      -1,   110,    56,   110,    -1,   110,    57,   110,    -1,   110,
-      43,   110,    -1,   110,    44,   110,    -1,   110,    42,   110,
-      -1,    58,   110,    -1,   110,    52,   110,    -1,   110,    51,
-     110,    -1,    94,    -1
+      61,    -1,    37,    19,    -1,    -1,    -1,    81,     4,    10,
+      76,    83,    62,    78,    79,    77,    80,    63,    -1,    -1,
+       7,    64,    85,    -1,    -1,     8,    64,    87,    -1,     9,
+      64,    96,    -1,    -1,    81,    82,    -1,     5,    -1,     6,
+      -1,    -1,    64,    84,    -1,    10,    -1,    84,    10,    -1,
+      86,    -1,    85,    86,    -1,    10,    65,    19,    -1,    10,
+      65,    16,    -1,    10,    65,    38,    -1,    10,    65,    39,
+      -1,    88,    -1,    87,    88,    -1,    11,    65,    19,    90,
+      -1,    -1,    11,    65,    89,    21,    90,    -1,    11,    65,
+      20,    -1,    -1,    90,    91,    -1,    23,    -1,    22,    -1,
+      24,    -1,    25,    -1,    10,    -1,    92,    66,    10,    -1,
+      92,    67,   111,    68,    -1,    92,    69,    93,    70,    -1,
+      -1,    94,    -1,    97,    -1,    94,    71,    97,    -1,    21,
+      -1,    97,    -1,    38,    -1,    39,    -1,   111,    35,    95,
+      -1,   111,    36,   111,    -1,    11,    -1,    11,    26,   111,
+      -1,    11,    31,   104,    -1,    -1,    -1,    33,   110,    10,
+      31,    98,   103,    64,    99,    69,    96,    70,    -1,    -1,
+      33,   110,    32,   106,    64,   100,    69,    96,    70,    -1,
+     110,    32,   106,    -1,    60,    96,    -1,    -1,    96,    41,
+     101,    96,    -1,    -1,    96,    40,   102,    96,    -1,   111,
+      50,   111,    -1,   111,    48,   111,    -1,   111,    49,   111,
+      -1,   111,    47,   111,    -1,   111,    46,   111,    -1,   111,
+      45,   111,    -1,   111,    -1,    69,    97,    70,    -1,    69,
+     105,    70,    -1,   104,    -1,    69,   111,     3,   111,    70,
+      -1,   111,    -1,   105,    71,   111,    -1,    -1,    69,   107,
+     108,    70,    -1,    34,    -1,   109,    -1,   108,    71,   109,
+      -1,    11,    -1,    15,    -1,   111,    -1,    29,    -1,    30,
+      -1,    69,   111,    70,    -1,    27,    -1,    28,    -1,    18,
+      69,   111,    70,    -1,    16,    -1,    17,    -1,    19,    -1,
+      12,    -1,    13,    67,   111,    68,    -1,    13,    -1,    14,
+      67,   111,    68,    -1,    14,    -1,    92,    -1,    54,   111,
+      -1,   111,    53,   111,    -1,   111,    54,   111,    -1,   111,
+      55,   111,    -1,   111,    56,   111,    -1,   111,    57,   111,
+      -1,   111,    43,   111,    -1,   111,    44,   111,    -1,   111,
+      42,   111,    -1,    58,   111,    -1,   111,    52,   111,    -1,
+     111,    51,   111,    -1,    95,    -1
 };
 
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint16 yyrline[] =
 {
        0,   200,   200,   202,   203,   204,   205,   206,   211,   224,
-     223,   248,   251,   279,   282,   309,   314,   315,   320,   321,
-     327,   330,   348,   361,   398,   399,   404,   420,   433,   446,
-     463,   464,   469,   480,   479,   495,   509,   510,   515,   516,
-     517,   518,   523,   608,   654,   712,   757,   758,   762,   787,
-     823,   869,   884,   893,   902,   917,   929,   943,   956,   968,
-     998,   967,  1114,  1113,  1193,  1199,  1206,  1205,  1268,  1267,
-    1328,  1337,  1346,  1355,  1364,  1373,  1382,  1386,  1394,  1395,
-    1400,  1422,  1434,  1450,  1449,  1455,  1466,  1467,  1472,  1479,
-    1490,  1491,  1495,  1503,  1507,  1517,  1531,  1547,  1557,  1566,
-    1590,  1602,  1614,  1630,  1642,  1658,  1702,  1721,  1739,  1757,
-    1775,  1801,  1819,  1829,  1839,  1849,  1859,  1869,  1879
+     233,   223,   256,   259,   287,   290,   317,   322,   323,   328,
+     329,   335,   338,   356,   369,   406,   407,   412,   428,   441,
+     454,   471,   472,   477,   488,   487,   503,   517,   518,   523,
+     524,   525,   526,   531,   616,   662,   720,   765,   766,   770,
+     795,   831,   877,   892,   901,   910,   925,   937,   951,   964,
+     976,  1006,   975,  1122,  1121,  1201,  1207,  1214,  1213,  1276,
+    1275,  1336,  1345,  1354,  1363,  1372,  1381,  1390,  1394,  1402,
+    1403,  1408,  1430,  1442,  1458,  1457,  1463,  1474,  1475,  1480,
+    1487,  1498,  1499,  1503,  1511,  1515,  1525,  1539,  1555,  1565,
+    1574,  1598,  1610,  1622,  1638,  1650,  1666,  1710,  1729,  1747,
+    1765,  1783,  1809,  1827,  1837,  1847,  1857,  1867,  1877,  1887
 };
 #endif
 
@@ -658,13 +658,13 @@ static const char *const yytname[] =
   "_LE_", "_LT_", "_SHIFT_RIGHT_", "_SHIFT_LEFT_", "'+'", "'-'", "'*'",
   "'\\\\'", "'%'", "'~'", "UNARY_MINUS", "_NOT_", "\"include\"", "'{'",
   "'}'", "':'", "'='", "'.'", "'['", "']'", "'('", "')'", "','", "$accept",
-  "rules", "import", "rule", "@1", "meta", "strings", "condition",
+  "rules", "import", "rule", "@1", "@2", "meta", "strings", "condition",
   "rule_modifiers", "rule_modifier", "tags", "tag_list",
   "meta_declarations", "meta_declaration", "string_declarations",
-  "string_declaration", "@2", "string_modifiers", "string_modifier",
+  "string_declaration", "@3", "string_modifiers", "string_modifier",
   "identifier", "arguments", "arguments_list", "regexp",
-  "boolean_expression", "expression", "@3", "@4", "@5", "@6", "@7",
-  "integer_set", "range", "integer_enumeration", "string_set", "@8",
+  "boolean_expression", "expression", "@4", "@5", "@6", "@7", "@8",
+  "integer_set", "range", "integer_enumeration", "string_set", "@9",
   "string_enumeration", "string_enumeration_item", "for_expression",
   "primary_expression", 0
 };
@@ -690,34 +690,34 @@ static const yytype_uint16 yytoknum[] =
 static const yytype_uint8 yyr1[] =
 {
        0,    72,    73,    73,    73,    73,    73,    73,    74,    76,
-      75,    77,    77,    78,    78,    79,    80,    80,    81,    81,
-      82,    82,    83,    83,    84,    84,    85,    85,    85,    85,
-      86,    86,    87,    88,    87,    87,    89,    89,    90,    90,
-      90,    90,    91,    91,    91,    91,    92,    92,    93,    93,
-      94,    95,    96,    96,    96,    96,    96,    96,    96,    97,
-      98,    96,    99,    96,    96,    96,   100,    96,   101,    96,
-      96,    96,    96,    96,    96,    96,    96,    96,   102,   102,
-     103,   104,   104,   106,   105,   105,   107,   107,   108,   108,
-     109,   109,   109,   110,   110,   110,   110,   110,   110,   110,
-     110,   110,   110,   110,   110,   110,   110,   110,   110,   110,
-     110,   110,   110,   110,   110,   110,   110,   110,   110
+      77,    75,    78,    78,    79,    79,    80,    81,    81,    82,
+      82,    83,    83,    84,    84,    85,    85,    86,    86,    86,
+      86,    87,    87,    88,    89,    88,    88,    90,    90,    91,
+      91,    91,    91,    92,    92,    92,    92,    93,    93,    94,
+      94,    95,    96,    97,    97,    97,    97,    97,    97,    97,
+      98,    99,    97,   100,    97,    97,    97,   101,    97,   102,
+      97,    97,    97,    97,    97,    97,    97,    97,    97,   103,
+     103,   104,   105,   105,   107,   106,   106,   108,   108,   109,
+     109,   110,   110,   110,   111,   111,   111,   111,   111,   111,
+     111,   111,   111,   111,   111,   111,   111,   111,   111,   111,
+     111,   111,   111,   111,   111,   111,   111,   111,   111,   111
 };
 
 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
 static const yytype_uint8 yyr2[] =
 {
        0,     2,     0,     2,     2,     3,     3,     3,     2,     0,
-      10,     0,     3,     0,     3,     3,     0,     2,     1,     1,
-       0,     2,     1,     2,     1,     2,     3,     3,     3,     3,
-       1,     2,     4,     0,     5,     3,     0,     2,     1,     1,
-       1,     1,     1,     3,     4,     4,     0,     1,     1,     3,
-       1,     1,     1,     1,     3,     3,     1,     3,     3,     0,
-       0,    11,     0,     9,     3,     2,     0,     4,     0,     4,
-       3,     3,     3,     3,     3,     3,     1,     3,     3,     1,
-       5,     1,     3,     0,     4,     1,     1,     3,     1,     1,
-       1,     1,     1,     3,     1,     1,     4,     1,     1,     1,
-       1,     4,     1,     4,     1,     1,     2,     3,     3,     3,
-       3,     3,     3,     3,     3,     2,     3,     3,     1
+       0,    11,     0,     3,     0,     3,     3,     0,     2,     1,
+       1,     0,     2,     1,     2,     1,     2,     3,     3,     3,
+       3,     1,     2,     4,     0,     5,     3,     0,     2,     1,
+       1,     1,     1,     1,     3,     4,     4,     0,     1,     1,
+       3,     1,     1,     1,     1,     3,     3,     1,     3,     3,
+       0,     0,    11,     0,     9,     3,     2,     0,     4,     0,
+       4,     3,     3,     3,     3,     3,     3,     1,     3,     3,
+       1,     5,     1,     3,     0,     4,     1,     1,     3,     1,
+       1,     1,     1,     1,     3,     1,     1,     4,     1,     1,
+       1,     1,     4,     1,     4,     1,     1,     2,     3,     3,
+       3,     3,     3,     3,     3,     3,     2,     3,     3,     1
 };
 
 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
@@ -725,142 +725,142 @@ static const yytype_uint8 yyr2[] =
    means the default is an error.  */
 static const yytype_uint8 yydefact[] =
 {
-       2,     0,     1,    16,     0,     4,     3,     0,     7,     6,
-       5,     8,     0,    18,    19,    17,    20,     0,     0,    22,
-      21,    11,    23,     0,    13,     0,     0,     9,     0,    12,
-      24,     0,     0,     0,    25,     0,    14,    30,     0,     0,
-      27,    26,    28,    29,    33,    31,     0,    10,    36,    35,
-       0,    42,    56,   100,   102,   104,    97,    98,     0,    99,
-      50,    94,    95,    91,    92,     0,    52,    53,     0,     0,
-       0,     0,   105,   118,    15,    51,     0,    76,    32,    36,
-       0,     0,     0,     0,     0,     0,     0,    90,   106,   115,
-      65,     0,    51,    76,     0,     0,    46,    68,    66,     0,
+       2,     0,     1,    17,     0,     4,     3,     0,     7,     6,
+       5,     8,     0,    19,    20,    18,     9,    21,     0,     0,
+      23,    22,    12,    24,     0,    14,     0,     0,    10,     0,
+      13,    25,     0,     0,     0,    26,     0,    15,    31,     0,
+       0,    28,    27,    29,    30,    34,    32,     0,    11,    37,
+      36,     0,    43,    57,   101,   103,   105,    98,    99,     0,
+     100,    51,    95,    96,    92,    93,     0,    53,    54,     0,
+       0,     0,     0,   106,   119,    16,    52,     0,    77,    33,
+      37,     0,     0,     0,     0,     0,     0,     0,    91,   107,
+     116,    66,     0,    52,    77,     0,     0,    47,    69,    67,
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,    39,    38,
-      40,    41,    37,    34,    57,     0,    58,     0,     0,     0,
-       0,     0,     0,    77,    93,    43,     0,     0,    47,    48,
-       0,     0,    85,    83,    64,    54,    55,   114,   112,   113,
-      75,    74,    73,    71,    72,    70,   117,   116,   107,   108,
-     109,   110,   111,     0,   101,   103,    96,    59,     0,    44,
-      45,     0,    69,    67,     0,     0,     0,    62,    49,    88,
-      89,     0,    86,     0,     0,     0,    79,     0,    84,     0,
-      80,     0,    81,    60,     0,    87,    78,     0,     0,     0,
-      82,     0,    63,     0,    61
+       0,     0,     0,     0,     0,     0,     0,     0,     0,    40,
+      39,    41,    42,    38,    35,    58,     0,    59,     0,     0,
+       0,     0,     0,     0,    78,    94,    44,     0,     0,    48,
+      49,     0,     0,    86,    84,    65,    55,    56,   115,   113,
+     114,    76,    75,    74,    72,    73,    71,   118,   117,   108,
+     109,   110,   111,   112,     0,   102,   104,    97,    60,     0,
+      45,    46,     0,    70,    68,     0,     0,     0,    63,    50,
+      89,    90,     0,    87,     0,     0,     0,    80,     0,    85,
+       0,    81,     0,    82,    61,     0,    88,    79,     0,     0,
+       0,    83,     0,    64,     0,    62
 };
 
 /* YYDEFGOTO[NTERM-NUM].  */
 static const yytype_int16 yydefgoto[] =
 {
-      -1,     1,     5,     6,    32,    24,    27,    39,     7,    15,
-      18,    20,    29,    30,    36,    37,    50,    78,   122,    72,
-     137,   138,    73,    91,    75,   176,   198,   187,   141,   140,
-     185,   126,   191,   144,   174,   181,   182,    76,    77
+      -1,     1,     5,     6,    17,    33,    25,    28,    40,     7,
+      15,    19,    21,    30,    31,    37,    38,    51,    79,   123,
+      73,   138,   139,    74,    92,    76,   177,   199,   188,   142,
+     141,   186,   127,   192,   145,   175,   182,   183,    77,    78
 };
 
 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
-#define YYPACT_NINF -70
+#define YYPACT_NINF -71
 static const yytype_int16 yypact[] =
 {
-     -70,    29,   -70,   -29,   -16,   -70,   -70,   166,   -70,   -70,
-     -70,   -70,    13,   -70,   -70,   -70,   -10,    60,    10,   -70,
-      91,    71,   -70,    16,    95,   121,    41,   -70,    42,   121,
-     -70,   126,   133,    70,   -70,    94,   126,   -70,   111,   114,
-     -70,   -70,   -70,   -70,    63,   -70,    46,   -70,   -70,   -70,
-     157,   -70,    -9,   -70,   115,   119,   -70,   -70,   112,   -70,
-     -70,   -70,   -70,   -70,   -70,   100,   -70,   -70,   122,   122,
-      46,    46,    30,   -70,    47,   -70,   155,   290,    68,   -70,
-     122,   120,   122,   122,   122,   122,    -4,   306,   -70,   -70,
-     -70,    47,   118,   167,   180,   122,    46,   -70,   -70,     2,
-     179,   122,   122,   122,   122,   122,   122,   122,   122,   122,
-     122,   122,   122,   122,   122,   122,   122,   122,   -70,   -70,
-     -70,   -70,   -70,    68,   306,   122,   -70,   227,   245,   109,
-     187,   170,     2,   -70,   -70,   -70,   263,   134,   135,   116,
-      46,    46,   -70,   -70,   -70,   -70,   306,   321,   335,   -42,
-     306,   306,   306,   306,   306,   306,    69,    69,    90,    90,
-     -70,   -70,   -70,   141,   -70,   -70,   -70,   -70,   143,   -70,
-     -70,    46,   164,   -70,    66,   122,   139,   -70,   116,   -70,
-     -70,    97,   -70,   207,   122,   161,   -70,   158,   -70,    66,
-     -70,   103,   141,   -70,    46,   -70,   -70,   122,   159,   -15,
-     306,    46,   -70,    28,   -70
+     -71,    29,   -71,   -29,   -16,   -71,   -71,   166,   -71,   -71,
+     -71,   -71,    13,   -71,   -71,   -71,   -71,   -10,    60,    10,
+     -71,    91,    71,   -71,    16,    95,   121,    41,   -71,    42,
+     121,   -71,   126,   133,    70,   -71,    94,   126,   -71,   111,
+     114,   -71,   -71,   -71,   -71,    63,   -71,    46,   -71,   -71,
+     -71,   157,   -71,    -9,   -71,   115,   119,   -71,   -71,   112,
+     -71,   -71,   -71,   -71,   -71,   -71,   100,   -71,   -71,   122,
+     122,    46,    46,    30,   -71,    47,   -71,   155,   290,    68,
+     -71,   122,   120,   122,   122,   122,   122,    -4,   306,   -71,
+     -71,   -71,    47,   118,   167,   180,   122,    46,   -71,   -71,
+       2,   179,   122,   122,   122,   122,   122,   122,   122,   122,
+     122,   122,   122,   122,   122,   122,   122,   122,   122,   -71,
+     -71,   -71,   -71,   -71,    68,   306,   122,   -71,   227,   245,
+     109,   187,   170,     2,   -71,   -71,   -71,   263,   134,   135,
+     116,    46,    46,   -71,   -71,   -71,   -71,   306,   321,   335,
+     -42,   306,   306,   306,   306,   306,   306,    69,    69,    90,
+      90,   -71,   -71,   -71,   141,   -71,   -71,   -71,   -71,   143,
+     -71,   -71,    46,   164,   -71,    66,   122,   139,   -71,   116,
+     -71,   -71,    97,   -71,   207,   122,   161,   -71,   158,   -71,
+      66,   -71,   103,   141,   -71,    46,   -71,   -71,   122,   159,
+     -15,   306,    46,   -71,    28,   -71
 };
 
 /* YYPGOTO[NTERM-NUM].  */
 static const yytype_int16 yypgoto[] =
 {
-     -70,   -70,   223,   229,   -70,   -70,   -70,   -70,   -70,   -70,
-     -70,   -70,   -70,   204,   -70,   198,   -70,   156,   -70,   -70,
-     -70,   -70,   136,   -46,   -69,   -70,   -70,   -70,   -70,   -70,
-     -70,    72,   -70,   113,   -70,   -70,    57,   182,   -64
+     -71,   -71,   223,   229,   -71,   -71,   -71,   -71,   -71,   -71,
+     -71,   -71,   -71,   -71,   203,   -71,   197,   -71,   156,   -71,
+     -71,   -71,   -71,   144,   -47,   -70,   -71,   -71,   -71,   -71,
+     -71,   -71,    58,   -71,   113,   -71,   -71,    57,   182,   -65
 };
 
 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
    positive, shift that token.  If negative, reduce the rule which
    number is the opposite.  If zero, do what YYDEFACT says.
    If YYTABLE_NINF, syntax error.  */
-#define YYTABLE_NINF -91
+#define YYTABLE_NINF -92
 static const yytype_int16 yytable[] =
 {
-      74,    87,    92,    11,    88,    89,   131,    93,     4,   111,
-     112,   113,   114,   115,   116,   117,   124,    80,   127,   128,
-     129,   130,    81,    16,    90,    97,    98,   139,   132,     2,
-       3,   136,     8,   -16,   -16,   -16,   142,   146,   147,   148,
-     149,   150,   151,   152,   153,   154,   155,   156,   157,   158,
-     159,   160,   161,   162,    17,   202,    51,    52,    53,    54,
-      55,   163,    56,    57,    58,    59,     4,    60,    97,    98,
-      19,   143,    21,    61,    62,    63,    64,   179,    23,    65,
-      25,   180,    48,    49,    66,    67,    40,    97,    98,    41,
-     118,   119,   120,   121,   172,   173,    94,    95,   204,    96,
-      68,    22,   178,    26,    69,    31,    70,    33,    42,    43,
-      51,   183,    53,    54,    55,    71,    56,    57,    58,    59,
-     192,    60,   113,   114,   115,   116,   117,    61,    62,    63,
-      64,    28,    51,   200,    53,    54,    55,    35,    56,    57,
-      58,    59,    38,    60,   175,   115,   116,   117,   199,    61,
-      62,   102,   103,   104,    68,   203,   -51,   -51,    69,    44,
-     111,   112,   113,   114,   115,   116,   117,   188,   189,    85,
-      12,    13,    14,   196,   197,    46,    68,    47,    79,   166,
-      69,    84,    82,   102,   103,   104,    83,    99,   133,   125,
-     135,    85,   111,   112,   113,   114,   115,   116,   117,   -90,
-      60,   167,   100,   101,   170,    98,   171,   177,   184,   102,
-     103,   104,   105,   106,   107,   108,   109,   110,   111,   112,
-     113,   114,   115,   116,   117,   193,     9,   194,   201,   102,
-     103,   104,    10,    34,    45,   123,   145,   134,   111,   112,
-     113,   114,   115,   116,   117,   168,   195,    86,   186,   102,
-     103,   104,     0,     0,     0,     0,     0,   134,   111,   112,
-     113,   114,   115,   116,   117,     0,     0,     0,     0,   102,
-     103,   104,     0,     0,     0,     0,     0,   190,   111,   112,
-     113,   114,   115,   116,   117,     0,     0,   102,   103,   104,
-       0,     0,     0,     0,     0,   164,   111,   112,   113,   114,
-     115,   116,   117,     0,     0,   102,   103,   104,     0,     0,
-       0,     0,     0,   165,   111,   112,   113,   114,   115,   116,
-     117,     0,   -90,     0,     0,   100,   101,     0,     0,     0,
-       0,   169,   102,   103,   104,   105,   106,   107,   108,   109,
-     110,   111,   112,   113,   114,   115,   116,   117,   102,   103,
-     104,     0,     0,     0,     0,     0,     0,   111,   112,   113,
-     114,   115,   116,   117,   103,   104,     0,     0,     0,     0,
-       0,     0,   111,   112,   113,   114,   115,   116,   117,   104,
-       0,     0,     0,     0,     0,     0,   111,   112,   113,   114,
-     115,   116,   117
+      75,    88,    93,    11,    89,    90,   132,    94,     4,   112,
+     113,   114,   115,   116,   117,   118,   125,    81,   128,   129,
+     130,   131,    82,    16,    91,    98,    99,   140,   133,     2,
+       3,   137,     8,   -17,   -17,   -17,   143,   147,   148,   149,
+     150,   151,   152,   153,   154,   155,   156,   157,   158,   159,
+     160,   161,   162,   163,    18,   203,    52,    53,    54,    55,
+      56,   164,    57,    58,    59,    60,     4,    61,    98,    99,
+      20,   144,    22,    62,    63,    64,    65,   180,    24,    66,
+      26,   181,    49,    50,    67,    68,    41,    98,    99,    42,
+     119,   120,   121,   122,   173,   174,    95,    96,   205,    97,
+      69,    23,   179,    27,    70,    32,    71,    34,    43,    44,
+      52,   184,    54,    55,    56,    72,    57,    58,    59,    60,
+     193,    61,   114,   115,   116,   117,   118,    62,    63,    64,
+      65,    29,    52,   201,    54,    55,    56,    36,    57,    58,
+      59,    60,    39,    61,   176,   116,   117,   118,   200,    62,
+      63,   103,   104,   105,    69,   204,   -52,   -52,    70,    45,
+     112,   113,   114,   115,   116,   117,   118,   189,   190,    86,
+      12,    13,    14,   197,   198,    47,    69,    48,    80,   167,
+      70,    85,    83,   103,   104,   105,    84,   100,   134,   126,
+     136,    86,   112,   113,   114,   115,   116,   117,   118,   -91,
+      61,   168,   101,   102,   171,    99,   172,   178,   185,   103,
+     104,   105,   106,   107,   108,   109,   110,   111,   112,   113,
+     114,   115,   116,   117,   118,   194,     9,   195,   202,   103,
+     104,   105,    10,    35,    46,   187,   124,   135,   112,   113,
+     114,   115,   116,   117,   118,   146,   169,   196,    87,   103,
+     104,   105,     0,     0,     0,     0,     0,   135,   112,   113,
+     114,   115,   116,   117,   118,     0,     0,     0,     0,   103,
+     104,   105,     0,     0,     0,     0,     0,   191,   112,   113,
+     114,   115,   116,   117,   118,     0,     0,   103,   104,   105,
+       0,     0,     0,     0,     0,   165,   112,   113,   114,   115,
+     116,   117,   118,     0,     0,   103,   104,   105,     0,     0,
+       0,     0,     0,   166,   112,   113,   114,   115,   116,   117,
+     118,     0,   -91,     0,     0,   101,   102,     0,     0,     0,
+       0,   170,   103,   104,   105,   106,   107,   108,   109,   110,
+     111,   112,   113,   114,   115,   116,   117,   118,   103,   104,
+     105,     0,     0,     0,     0,     0,     0,   112,   113,   114,
+     115,   116,   117,   118,   104,   105,     0,     0,     0,     0,
+       0,     0,   112,   113,   114,   115,   116,   117,   118,   105,
+       0,     0,     0,     0,     0,     0,   112,   113,   114,   115,
+     116,   117,   118
 };
 
 static const yytype_int16 yycheck[] =
 {
-      46,    65,    71,    19,    68,    69,    10,    71,    37,    51,
-      52,    53,    54,    55,    56,    57,    80,    26,    82,    83,
-      84,    85,    31,    10,    70,    40,    41,    96,    32,     0,
-       1,    95,    61,     4,     5,     6,    34,   101,   102,   103,
-     104,   105,   106,   107,   108,   109,   110,   111,   112,   113,
-     114,   115,   116,   117,    64,    70,    10,    11,    12,    13,
-      14,   125,    16,    17,    18,    19,    37,    21,    40,    41,
+      47,    66,    72,    19,    69,    70,    10,    72,    37,    51,
+      52,    53,    54,    55,    56,    57,    81,    26,    83,    84,
+      85,    86,    31,    10,    71,    40,    41,    97,    32,     0,
+       1,    96,    61,     4,     5,     6,    34,   102,   103,   104,
+     105,   106,   107,   108,   109,   110,   111,   112,   113,   114,
+     115,   116,   117,   118,    64,    70,    10,    11,    12,    13,
+      14,   126,    16,    17,    18,    19,    37,    21,    40,    41,
       10,    69,    62,    27,    28,    29,    30,    11,     7,    33,
       64,    15,    19,    20,    38,    39,    16,    40,    41,    19,
-      22,    23,    24,    25,   140,   141,    66,    67,    70,    69,
-      54,    10,   171,     8,    58,    64,    60,    65,    38,    39,
-      10,   175,    12,    13,    14,    69,    16,    17,    18,    19,
-     184,    21,    53,    54,    55,    56,    57,    27,    28,    29,
-      30,    10,    10,   197,    12,    13,    14,    11,    16,    17,
-      18,    19,     9,    21,     3,    55,    56,    57,   194,    27,
-      28,    42,    43,    44,    54,   201,    40,    41,    58,    65,
+      22,    23,    24,    25,   141,   142,    66,    67,    70,    69,
+      54,    10,   172,     8,    58,    64,    60,    65,    38,    39,
+      10,   176,    12,    13,    14,    69,    16,    17,    18,    19,
+     185,    21,    53,    54,    55,    56,    57,    27,    28,    29,
+      30,    10,    10,   198,    12,    13,    14,    11,    16,    17,
+      18,    19,     9,    21,     3,    55,    56,    57,   195,    27,
+      28,    42,    43,    44,    54,   202,    40,    41,    58,    65,
       51,    52,    53,    54,    55,    56,    57,    70,    71,    69,
        4,     5,     6,    70,    71,    64,    54,    63,    21,    70,
       58,    69,    67,    42,    43,    44,    67,    32,    70,    69,
@@ -868,8 +868,8 @@ static const yytype_int16 yycheck[] =
       21,    31,    35,    36,    70,    41,    71,    64,    69,    42,
       43,    44,    45,    46,    47,    48,    49,    50,    51,    52,
       53,    54,    55,    56,    57,    64,     3,    69,    69,    42,
-      43,    44,     3,    29,    36,    79,   100,    70,    51,    52,
-      53,    54,    55,    56,    57,   132,   189,    65,   176,    42,
+      43,    44,     3,    30,    37,   177,    80,    70,    51,    52,
+      53,    54,    55,    56,    57,   101,   133,   190,    66,    42,
       43,    44,    -1,    -1,    -1,    -1,    -1,    70,    51,    52,
       53,    54,    55,    56,    57,    -1,    -1,    -1,    -1,    42,
       43,    44,    -1,    -1,    -1,    -1,    -1,    70,    51,    52,
@@ -891,27 +891,27 @@ static const yytype_int16 yycheck[] =
    symbol of state STATE-NUM.  */
 static const yytype_uint8 yystos[] =
 {
-       0,    73,     0,     1,    37,    74,    75,    80,    61,    74,
-      75,    19,     4,     5,     6,    81,    10,    64,    82,    10,
-      83,    62,    10,     7,    77,    64,     8,    78,    10,    84,
-      85,    64,    76,    65,    85,    11,    86,    87,     9,    79,
-      16,    19,    38,    39,    65,    87,    64,    63,    19,    20,
-      88,    10,    11,    12,    13,    14,    16,    17,    18,    19,
-      21,    27,    28,    29,    30,    33,    38,    39,    54,    58,
-      60,    69,    91,    94,    95,    96,   109,   110,    89,    21,
-      26,    31,    67,    67,    69,    69,   109,   110,   110,   110,
-      95,    95,    96,   110,    66,    67,    69,    40,    41,    32,
-      35,    36,    42,    43,    44,    45,    46,    47,    48,    49,
-      50,    51,    52,    53,    54,    55,    56,    57,    22,    23,
-      24,    25,    90,    89,   110,    69,   103,   110,   110,   110,
-     110,    10,    32,    70,    70,    10,   110,    92,    93,    96,
-     101,   100,    34,    69,   105,    94,   110,   110,   110,   110,
-     110,   110,   110,   110,   110,   110,   110,   110,   110,   110,
-     110,   110,   110,   110,    68,    68,    70,    31,   105,    68,
-      70,    71,    95,    95,   106,     3,    97,    64,    96,    11,
-      15,   107,   108,   110,    69,   102,   103,    99,    70,    71,
-      70,   104,   110,    64,    69,   108,    70,    71,    98,    95,
-     110,    69,    70,    95,    70
+       0,    73,     0,     1,    37,    74,    75,    81,    61,    74,
+      75,    19,     4,     5,     6,    82,    10,    76,    64,    83,
+      10,    84,    62,    10,     7,    78,    64,     8,    79,    10,
+      85,    86,    64,    77,    65,    86,    11,    87,    88,     9,
+      80,    16,    19,    38,    39,    65,    88,    64,    63,    19,
+      20,    89,    10,    11,    12,    13,    14,    16,    17,    18,
+      19,    21,    27,    28,    29,    30,    33,    38,    39,    54,
+      58,    60,    69,    92,    95,    96,    97,   110,   111,    90,
+      21,    26,    31,    67,    67,    69,    69,   110,   111,   111,
+     111,    96,    96,    97,   111,    66,    67,    69,    40,    41,
+      32,    35,    36,    42,    43,    44,    45,    46,    47,    48,
+      49,    50,    51,    52,    53,    54,    55,    56,    57,    22,
+      23,    24,    25,    91,    90,   111,    69,   104,   111,   111,
+     111,   111,    10,    32,    70,    70,    10,   111,    93,    94,
+      97,   102,   101,    34,    69,   106,    95,   111,   111,   111,
+     111,   111,   111,   111,   111,   111,   111,   111,   111,   111,
+     111,   111,   111,   111,   111,    68,    68,    70,    31,   106,
+      68,    70,    71,    96,    96,   107,     3,    98,    64,    97,
+      11,    15,   108,   109,   111,    69,   103,   104,   100,    70,
+      71,    70,   105,   111,    64,    69,   109,    70,    71,    99,
+      96,   111,    69,    70,    96,    70
 };
 
 #define yyerrok		(yyerrstatus = 0)
@@ -1798,7 +1798,7 @@ yyreduce:
 #line 224 "grammar.y"
     {
         YR_RULE* rule = yr_parser_reduce_rule_declaration_phase_1(
-            yyscanner, (int32_t) (yyvsp[(1) - (7)].integer), (yyvsp[(3) - (7)].c_string), (yyvsp[(4) - (7)].c_string), (yyvsp[(7) - (7)].string), (yyvsp[(6) - (7)].meta));
+            yyscanner, (int32_t) (yyvsp[(1) - (3)].integer), (yyvsp[(3) - (3)].c_string));
 
         ERROR_IF(rule == NULL);
 
@@ -1809,26 +1809,37 @@ yyreduce:
   case 10:
 #line 233 "grammar.y"
     {
-        YR_RULE* rule = (yyvsp[(8) - (10)].rule); // rule created in phase 1
+        YR_RULE* rule = (yyvsp[(6) - (8)].rule); // rule created in phase 1
+
+        rule->tags = (yyvsp[(5) - (8)].c_string);
+        rule->metas = (yyvsp[(7) - (8)].meta);
+        rule->strings = (yyvsp[(8) - (8)].string);
+      }
+    break;
+
+  case 11:
+#line 241 "grammar.y"
+    {
+        YR_RULE* rule = (yyvsp[(6) - (11)].rule); // rule created in phase 1
 
         compiler->last_result = yr_parser_reduce_rule_declaration_phase_2(
             yyscanner, rule);
 
-        yr_free((yyvsp[(3) - (10)].c_string));
+        yr_free((yyvsp[(3) - (11)].c_string));
 
         ERROR_IF(compiler->last_result != ERROR_SUCCESS);
       }
     break;
 
-  case 11:
-#line 248 "grammar.y"
+  case 12:
+#line 256 "grammar.y"
     {
         (yyval.meta) = NULL;
       }
     break;
 
-  case 12:
-#line 252 "grammar.y"
+  case 13:
+#line 260 "grammar.y"
     {
         // Each rule have a list of meta-data info, consisting in a
         // sequence of YR_META structures. The last YR_META structure does
@@ -1853,15 +1864,15 @@ yyreduce:
       }
     break;
 
-  case 13:
-#line 279 "grammar.y"
+  case 14:
+#line 287 "grammar.y"
     {
         (yyval.string) = NULL;
       }
     break;
 
-  case 14:
-#line 283 "grammar.y"
+  case 15:
+#line 291 "grammar.y"
     {
         // Each rule have a list of strings, consisting in a sequence
         // of YR_STRING structures. The last YR_STRING structure does not
@@ -1886,35 +1897,35 @@ yyreduce:
       }
     break;
 
-  case 16:
-#line 314 "grammar.y"
+  case 17:
+#line 322 "grammar.y"
     { (yyval.integer) = 0;  }
     break;
 
-  case 17:
-#line 315 "grammar.y"
+  case 18:
+#line 323 "grammar.y"
     { (yyval.integer) = (yyvsp[(1) - (2)].integer) | (yyvsp[(2) - (2)].integer); }
     break;
 
-  case 18:
-#line 320 "grammar.y"
+  case 19:
+#line 328 "grammar.y"
     { (yyval.integer) = RULE_GFLAGS_PRIVATE; }
     break;
 
-  case 19:
-#line 321 "grammar.y"
+  case 20:
+#line 329 "grammar.y"
     { (yyval.integer) = RULE_GFLAGS_GLOBAL; }
     break;
 
-  case 20:
-#line 327 "grammar.y"
+  case 21:
+#line 335 "grammar.y"
     {
         (yyval.c_string) = NULL;
       }
     break;
 
-  case 21:
-#line 331 "grammar.y"
+  case 22:
+#line 339 "grammar.y"
     {
         // Tags list is represented in the arena as a sequence
         // of null-terminated strings, the sequence ends with an
@@ -1930,8 +1941,8 @@ yyreduce:
       }
     break;
 
-  case 22:
-#line 349 "grammar.y"
+  case 23:
+#line 357 "grammar.y"
     {
         char* identifier;
 
@@ -1946,8 +1957,8 @@ yyreduce:
       }
     break;
 
-  case 23:
-#line 362 "grammar.y"
+  case 24:
+#line 370 "grammar.y"
     {
         char* tag_name = (yyvsp[(1) - (2)].c_string);
         size_t tag_length = tag_name != NULL ? strlen(tag_name) : 0;
@@ -1981,18 +1992,18 @@ yyreduce:
       }
     break;
 
-  case 24:
-#line 398 "grammar.y"
+  case 25:
+#line 406 "grammar.y"
     {  (yyval.meta) = (yyvsp[(1) - (1)].meta); }
     break;
 
-  case 25:
-#line 399 "grammar.y"
+  case 26:
+#line 407 "grammar.y"
     {  (yyval.meta) = (yyvsp[(1) - (2)].meta); }
     break;
 
-  case 26:
-#line 405 "grammar.y"
+  case 27:
+#line 413 "grammar.y"
     {
         SIZED_STRING* sized_string = (yyvsp[(3) - (3)].sized_string);
 
@@ -2010,8 +2021,8 @@ yyreduce:
       }
     break;
 
-  case 27:
-#line 421 "grammar.y"
+  case 28:
+#line 429 "grammar.y"
     {
         (yyval.meta) = yr_parser_reduce_meta_declaration(
             yyscanner,
@@ -2026,8 +2037,8 @@ yyreduce:
       }
     break;
 
-  case 28:
-#line 434 "grammar.y"
+  case 29:
+#line 442 "grammar.y"
     {
         (yyval.meta) = yr_parser_reduce_meta_declaration(
             yyscanner,
@@ -2042,8 +2053,8 @@ yyreduce:
       }
     break;
 
-  case 29:
-#line 447 "grammar.y"
+  case 30:
+#line 455 "grammar.y"
     {
         (yyval.meta) = yr_parser_reduce_meta_declaration(
             yyscanner,
@@ -2058,18 +2069,18 @@ yyreduce:
       }
     break;
 
-  case 30:
-#line 463 "grammar.y"
+  case 31:
+#line 471 "grammar.y"
     { (yyval.string) = (yyvsp[(1) - (1)].string); }
     break;
 
-  case 31:
-#line 464 "grammar.y"
+  case 32:
+#line 472 "grammar.y"
     { (yyval.string) = (yyvsp[(1) - (2)].string); }
     break;
 
-  case 32:
-#line 470 "grammar.y"
+  case 33:
+#line 478 "grammar.y"
     {
         (yyval.string) = yr_parser_reduce_string_declaration(
             yyscanner, (int32_t) (yyvsp[(4) - (4)].integer), (yyvsp[(1) - (4)].c_string), (yyvsp[(3) - (4)].sized_string));
@@ -2081,15 +2092,15 @@ yyreduce:
       }
     break;
 
-  case 33:
-#line 480 "grammar.y"
+  case 34:
+#line 488 "grammar.y"
     {
         compiler->error_line = yyget_lineno(yyscanner);
       }
     break;
 
-  case 34:
-#line 484 "grammar.y"
+  case 35:
+#line 492 "grammar.y"
     {
         (yyval.string) = yr_parser_reduce_string_declaration(
             yyscanner, (int32_t) (yyvsp[(5) - (5)].integer) | STRING_GFLAGS_REGEXP, (yyvsp[(1) - (5)].c_string), (yyvsp[(4) - (5)].sized_string));
@@ -2103,8 +2114,8 @@ yyreduce:
       }
     break;
 
-  case 35:
-#line 496 "grammar.y"
+  case 36:
+#line 504 "grammar.y"
     {
         (yyval.string) = yr_parser_reduce_string_declaration(
             yyscanner, STRING_GFLAGS_HEXADECIMAL, (yyvsp[(1) - (3)].c_string), (yyvsp[(3) - (3)].sized_string));
@@ -2116,38 +2127,38 @@ yyreduce:
       }
     break;
 
-  case 36:
-#line 509 "grammar.y"
+  case 37:
+#line 517 "grammar.y"
     { (yyval.integer) = 0; }
     break;
 
-  case 37:
-#line 510 "grammar.y"
+  case 38:
+#line 518 "grammar.y"
     { (yyval.integer) = (yyvsp[(1) - (2)].integer) | (yyvsp[(2) - (2)].integer); }
     break;
 
-  case 38:
-#line 515 "grammar.y"
+  case 39:
+#line 523 "grammar.y"
     { (yyval.integer) = STRING_GFLAGS_WIDE; }
     break;
 
-  case 39:
-#line 516 "grammar.y"
+  case 40:
+#line 524 "grammar.y"
     { (yyval.integer) = STRING_GFLAGS_ASCII; }
     break;
 
-  case 40:
-#line 517 "grammar.y"
+  case 41:
+#line 525 "grammar.y"
     { (yyval.integer) = STRING_GFLAGS_NO_CASE; }
     break;
 
-  case 41:
-#line 518 "grammar.y"
+  case 42:
+#line 526 "grammar.y"
     { (yyval.integer) = STRING_GFLAGS_FULL_WORD; }
     break;
 
-  case 42:
-#line 524 "grammar.y"
+  case 43:
+#line 532 "grammar.y"
     {
         int var_index = yr_parser_lookup_loop_variable(yyscanner, (yyvsp[(1) - (1)].c_string));
 
@@ -2234,8 +2245,8 @@ yyreduce:
       }
     break;
 
-  case 43:
-#line 609 "grammar.y"
+  case 44:
+#line 617 "grammar.y"
     {
         YR_OBJECT* field = NULL;
 
@@ -2283,8 +2294,8 @@ yyreduce:
       }
     break;
 
-  case 44:
-#line 655 "grammar.y"
+  case 45:
+#line 663 "grammar.y"
     {
         YR_OBJECT_ARRAY* array;
         YR_OBJECT_DICTIONARY* dict;
@@ -2343,8 +2354,8 @@ yyreduce:
       }
     break;
 
-  case 45:
-#line 713 "grammar.y"
+  case 46:
+#line 721 "grammar.y"
     {
         YR_OBJECT_FUNCTION* function;
         char* args_fmt;
@@ -2387,18 +2398,18 @@ yyreduce:
       }
     break;
 
-  case 46:
-#line 757 "grammar.y"
+  case 47:
+#line 765 "grammar.y"
     { (yyval.c_string) = yr_strdup(""); }
     break;
 
-  case 47:
-#line 758 "grammar.y"
+  case 48:
+#line 766 "grammar.y"
     { (yyval.c_string) = (yyvsp[(1) - (1)].c_string); }
     break;
 
-  case 48:
-#line 763 "grammar.y"
+  case 49:
+#line 771 "grammar.y"
     {
         (yyval.c_string) = (char*) yr_malloc(MAX_FUNCTION_ARGS + 1);
 
@@ -2425,8 +2436,8 @@ yyreduce:
       }
     break;
 
-  case 49:
-#line 788 "grammar.y"
+  case 50:
+#line 796 "grammar.y"
     {
         if (strlen((yyvsp[(1) - (3)].c_string)) == MAX_FUNCTION_ARGS)
         {
@@ -2460,8 +2471,8 @@ yyreduce:
       }
     break;
 
-  case 50:
-#line 824 "grammar.y"
+  case 51:
+#line 832 "grammar.y"
     {
         SIZED_STRING* sized_string = (yyvsp[(1) - (1)].sized_string);
         RE* re;
@@ -2505,8 +2516,8 @@ yyreduce:
       }
     break;
 
-  case 51:
-#line 870 "grammar.y"
+  case 52:
+#line 878 "grammar.y"
     {
         if ((yyvsp[(1) - (1)].expression).type == EXPRESSION_TYPE_STRING)
         {
@@ -2520,8 +2531,8 @@ yyreduce:
       }
     break;
 
-  case 52:
-#line 885 "grammar.y"
+  case 53:
+#line 893 "grammar.y"
     {
         compiler->last_result = yr_parser_emit_with_arg(
             yyscanner, OP_PUSH, 1, NULL, NULL);
@@ -2532,8 +2543,8 @@ yyreduce:
       }
     break;
 
-  case 53:
-#line 894 "grammar.y"
+  case 54:
+#line 902 "grammar.y"
     {
         compiler->last_result = yr_parser_emit_with_arg(
             yyscanner, OP_PUSH, 0, NULL, NULL);
@@ -2544,8 +2555,8 @@ yyreduce:
       }
     break;
 
-  case 54:
-#line 903 "grammar.y"
+  case 55:
+#line 911 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(1) - (3)].expression), EXPRESSION_TYPE_STRING, "matches");
         CHECK_TYPE((yyvsp[(3) - (3)].expression), EXPRESSION_TYPE_REGEXP, "matches");
@@ -2562,8 +2573,8 @@ yyreduce:
       }
     break;
 
-  case 55:
-#line 918 "grammar.y"
+  case 56:
+#line 926 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(1) - (3)].expression), EXPRESSION_TYPE_STRING, "contains");
         CHECK_TYPE((yyvsp[(3) - (3)].expression), EXPRESSION_TYPE_STRING, "contains");
@@ -2577,8 +2588,8 @@ yyreduce:
       }
     break;
 
-  case 56:
-#line 930 "grammar.y"
+  case 57:
+#line 938 "grammar.y"
     {
         int result = yr_parser_reduce_string_identifier(
             yyscanner,
@@ -2594,8 +2605,8 @@ yyreduce:
       }
     break;
 
-  case 57:
-#line 944 "grammar.y"
+  case 58:
+#line 952 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(3) - (3)].expression), EXPRESSION_TYPE_INTEGER, "at");
 
@@ -2610,8 +2621,8 @@ yyreduce:
       }
     break;
 
-  case 58:
-#line 957 "grammar.y"
+  case 59:
+#line 965 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_string_identifier(
             yyscanner, (yyvsp[(1) - (3)].c_string), OP_FOUND_IN, UNDEFINED);
@@ -2624,8 +2635,8 @@ yyreduce:
       }
     break;
 
-  case 59:
-#line 968 "grammar.y"
+  case 60:
+#line 976 "grammar.y"
     {
         int var_index;
 
@@ -2657,8 +2668,8 @@ yyreduce:
       }
     break;
 
-  case 60:
-#line 998 "grammar.y"
+  case 61:
+#line 1006 "grammar.y"
     {
         int mem_offset = LOOP_LOCAL_VARS * compiler->loop_depth;
         uint8_t* addr;
@@ -2695,8 +2706,8 @@ yyreduce:
       }
     break;
 
-  case 61:
-#line 1033 "grammar.y"
+  case 62:
+#line 1041 "grammar.y"
     {
         int mem_offset;
 
@@ -2779,8 +2790,8 @@ yyreduce:
       }
     break;
 
-  case 62:
-#line 1114 "grammar.y"
+  case 63:
+#line 1122 "grammar.y"
     {
         int mem_offset = LOOP_LOCAL_VARS * compiler->loop_depth;
         uint8_t* addr;
@@ -2812,8 +2823,8 @@ yyreduce:
       }
     break;
 
-  case 63:
-#line 1144 "grammar.y"
+  case 64:
+#line 1152 "grammar.y"
     {
         int mem_offset;
 
@@ -2865,8 +2876,8 @@ yyreduce:
       }
     break;
 
-  case 64:
-#line 1194 "grammar.y"
+  case 65:
+#line 1202 "grammar.y"
     {
         yr_parser_emit(yyscanner, OP_OF, NULL);
 
@@ -2874,8 +2885,8 @@ yyreduce:
       }
     break;
 
-  case 65:
-#line 1200 "grammar.y"
+  case 66:
+#line 1208 "grammar.y"
     {
         yr_parser_emit(yyscanner, OP_NOT, NULL);
 
@@ -2883,8 +2894,8 @@ yyreduce:
       }
     break;
 
-  case 66:
-#line 1206 "grammar.y"
+  case 67:
+#line 1214 "grammar.y"
     {
         YR_FIXUP* fixup;
         int64_t* jmp_destination_addr;
@@ -2912,8 +2923,8 @@ yyreduce:
       }
     break;
 
-  case 67:
-#line 1232 "grammar.y"
+  case 68:
+#line 1240 "grammar.y"
     {
         YR_FIXUP* fixup;
         uint8_t* and_addr;
@@ -2951,8 +2962,8 @@ yyreduce:
       }
     break;
 
-  case 68:
-#line 1268 "grammar.y"
+  case 69:
+#line 1276 "grammar.y"
     {
         YR_FIXUP* fixup;
         int64_t* jmp_destination_addr;
@@ -2979,8 +2990,8 @@ yyreduce:
       }
     break;
 
-  case 69:
-#line 1293 "grammar.y"
+  case 70:
+#line 1301 "grammar.y"
     {
         YR_FIXUP* fixup;
         uint8_t* or_addr;
@@ -3018,8 +3029,8 @@ yyreduce:
       }
     break;
 
-  case 70:
-#line 1329 "grammar.y"
+  case 71:
+#line 1337 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, "<", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3030,8 +3041,8 @@ yyreduce:
       }
     break;
 
-  case 71:
-#line 1338 "grammar.y"
+  case 72:
+#line 1346 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, ">", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3042,8 +3053,8 @@ yyreduce:
       }
     break;
 
-  case 72:
-#line 1347 "grammar.y"
+  case 73:
+#line 1355 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, "<=", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3054,8 +3065,8 @@ yyreduce:
       }
     break;
 
-  case 73:
-#line 1356 "grammar.y"
+  case 74:
+#line 1364 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, ">=", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3066,8 +3077,8 @@ yyreduce:
       }
     break;
 
-  case 74:
-#line 1365 "grammar.y"
+  case 75:
+#line 1373 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, "==", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3078,8 +3089,8 @@ yyreduce:
       }
     break;
 
-  case 75:
-#line 1374 "grammar.y"
+  case 76:
+#line 1382 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, "!=", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3090,32 +3101,32 @@ yyreduce:
       }
     break;
 
-  case 76:
-#line 1383 "grammar.y"
+  case 77:
+#line 1391 "grammar.y"
     {
         (yyval.expression) = (yyvsp[(1) - (1)].expression);
       }
     break;
 
-  case 77:
-#line 1387 "grammar.y"
+  case 78:
+#line 1395 "grammar.y"
     {
         (yyval.expression) = (yyvsp[(2) - (3)].expression);
       }
     break;
 
-  case 78:
-#line 1394 "grammar.y"
+  case 79:
+#line 1402 "grammar.y"
     { (yyval.integer) = INTEGER_SET_ENUMERATION; }
     break;
 
-  case 79:
-#line 1395 "grammar.y"
+  case 80:
+#line 1403 "grammar.y"
     { (yyval.integer) = INTEGER_SET_RANGE; }
     break;
 
-  case 80:
-#line 1401 "grammar.y"
+  case 81:
+#line 1409 "grammar.y"
     {
         if ((yyvsp[(2) - (5)].expression).type != EXPRESSION_TYPE_INTEGER)
         {
@@ -3135,8 +3146,8 @@ yyreduce:
       }
     break;
 
-  case 81:
-#line 1423 "grammar.y"
+  case 82:
+#line 1431 "grammar.y"
     {
         if ((yyvsp[(1) - (1)].expression).type != EXPRESSION_TYPE_INTEGER)
         {
@@ -3150,8 +3161,8 @@ yyreduce:
       }
     break;
 
-  case 82:
-#line 1435 "grammar.y"
+  case 83:
+#line 1443 "grammar.y"
     {
         if ((yyvsp[(3) - (3)].expression).type != EXPRESSION_TYPE_INTEGER)
         {
@@ -3164,16 +3175,16 @@ yyreduce:
       }
     break;
 
-  case 83:
-#line 1450 "grammar.y"
+  case 84:
+#line 1458 "grammar.y"
     {
         // Push end-of-list marker
         yr_parser_emit_with_arg(yyscanner, OP_PUSH, UNDEFINED, NULL, NULL);
       }
     break;
 
-  case 85:
-#line 1456 "grammar.y"
+  case 86:
+#line 1464 "grammar.y"
     {
         yr_parser_emit_with_arg(yyscanner, OP_PUSH, UNDEFINED, NULL, NULL);
         yr_parser_emit_pushes_for_strings(yyscanner, "$*");
@@ -3182,8 +3193,8 @@ yyreduce:
       }
     break;
 
-  case 88:
-#line 1473 "grammar.y"
+  case 89:
+#line 1481 "grammar.y"
     {
         yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[(1) - (1)].c_string));
         yr_free((yyvsp[(1) - (1)].c_string));
@@ -3192,8 +3203,8 @@ yyreduce:
       }
     break;
 
-  case 89:
-#line 1480 "grammar.y"
+  case 90:
+#line 1488 "grammar.y"
     {
         yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[(1) - (1)].c_string));
         yr_free((yyvsp[(1) - (1)].c_string));
@@ -3202,29 +3213,29 @@ yyreduce:
       }
     break;
 
-  case 91:
-#line 1492 "grammar.y"
+  case 92:
+#line 1500 "grammar.y"
     {
         yr_parser_emit_with_arg(yyscanner, OP_PUSH, UNDEFINED, NULL, NULL);
       }
     break;
 
-  case 92:
-#line 1496 "grammar.y"
+  case 93:
+#line 1504 "grammar.y"
     {
         yr_parser_emit_with_arg(yyscanner, OP_PUSH, 1, NULL, NULL);
       }
     break;
 
-  case 93:
-#line 1504 "grammar.y"
+  case 94:
+#line 1512 "grammar.y"
     {
         (yyval.expression) = (yyvsp[(2) - (3)].expression);
       }
     break;
 
-  case 94:
-#line 1508 "grammar.y"
+  case 95:
+#line 1516 "grammar.y"
     {
         compiler->last_result = yr_parser_emit(
             yyscanner, OP_FILESIZE, NULL);
@@ -3236,8 +3247,8 @@ yyreduce:
       }
     break;
 
-  case 95:
-#line 1518 "grammar.y"
+  case 96:
+#line 1526 "grammar.y"
     {
         yywarning(yyscanner,
             "Using deprecated \"entrypoint\" keyword. Use the \"entry_point\" "
@@ -3253,8 +3264,8 @@ yyreduce:
       }
     break;
 
-  case 96:
-#line 1532 "grammar.y"
+  case 97:
+#line 1540 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(3) - (4)].expression), EXPRESSION_TYPE_INTEGER, "intXXXX or uintXXXX");
 
@@ -3272,8 +3283,8 @@ yyreduce:
       }
     break;
 
-  case 97:
-#line 1548 "grammar.y"
+  case 98:
+#line 1556 "grammar.y"
     {
         compiler->last_result = yr_parser_emit_with_arg(
             yyscanner, OP_PUSH, (yyvsp[(1) - (1)].integer), NULL, NULL);
@@ -3285,8 +3296,8 @@ yyreduce:
       }
     break;
 
-  case 98:
-#line 1558 "grammar.y"
+  case 99:
+#line 1566 "grammar.y"
     {
         compiler->last_result = yr_parser_emit_with_arg_double(
             yyscanner, OP_PUSH, (yyvsp[(1) - (1)].double_), NULL, NULL);
@@ -3297,8 +3308,8 @@ yyreduce:
       }
     break;
 
-  case 99:
-#line 1567 "grammar.y"
+  case 100:
+#line 1575 "grammar.y"
     {
         SIZED_STRING* sized_string;
 
@@ -3324,8 +3335,8 @@ yyreduce:
       }
     break;
 
-  case 100:
-#line 1591 "grammar.y"
+  case 101:
+#line 1599 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_string_identifier(
             yyscanner, (yyvsp[(1) - (1)].c_string), OP_COUNT, UNDEFINED);
@@ -3339,8 +3350,8 @@ yyreduce:
       }
     break;
 
-  case 101:
-#line 1603 "grammar.y"
+  case 102:
+#line 1611 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_string_identifier(
             yyscanner, (yyvsp[(1) - (4)].c_string), OP_OFFSET, UNDEFINED);
@@ -3354,8 +3365,8 @@ yyreduce:
       }
     break;
 
-  case 102:
-#line 1615 "grammar.y"
+  case 103:
+#line 1623 "grammar.y"
     {
         compiler->last_result = yr_parser_emit_with_arg(
             yyscanner, OP_PUSH, 1, NULL, NULL);
@@ -3373,8 +3384,8 @@ yyreduce:
       }
     break;
 
-  case 103:
-#line 1631 "grammar.y"
+  case 104:
+#line 1639 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_string_identifier(
             yyscanner, (yyvsp[(1) - (4)].c_string), OP_LENGTH, UNDEFINED);
@@ -3388,8 +3399,8 @@ yyreduce:
       }
     break;
 
-  case 104:
-#line 1643 "grammar.y"
+  case 105:
+#line 1651 "grammar.y"
     {
         compiler->last_result = yr_parser_emit_with_arg(
             yyscanner, OP_PUSH, 1, NULL, NULL);
@@ -3407,8 +3418,8 @@ yyreduce:
       }
     break;
 
-  case 105:
-#line 1659 "grammar.y"
+  case 106:
+#line 1667 "grammar.y"
     {
         if ((yyvsp[(1) - (1)].expression).type == EXPRESSION_TYPE_INTEGER)  // loop identifier
         {
@@ -3454,8 +3465,8 @@ yyreduce:
       }
     break;
 
-  case 106:
-#line 1703 "grammar.y"
+  case 107:
+#line 1711 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(2) - (2)].expression), EXPRESSION_TYPE_INTEGER | EXPRESSION_TYPE_FLOAT, "-");
 
@@ -3476,8 +3487,8 @@ yyreduce:
       }
     break;
 
-  case 107:
-#line 1722 "grammar.y"
+  case 108:
+#line 1730 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, "+", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3497,8 +3508,8 @@ yyreduce:
       }
     break;
 
-  case 108:
-#line 1740 "grammar.y"
+  case 109:
+#line 1748 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, "-", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3518,8 +3529,8 @@ yyreduce:
       }
     break;
 
-  case 109:
-#line 1758 "grammar.y"
+  case 110:
+#line 1766 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, "*", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3539,8 +3550,8 @@ yyreduce:
       }
     break;
 
-  case 110:
-#line 1776 "grammar.y"
+  case 111:
+#line 1784 "grammar.y"
     {
         compiler->last_result = yr_parser_reduce_operation(
             yyscanner, "\\", (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression));
@@ -3568,8 +3579,8 @@ yyreduce:
       }
     break;
 
-  case 111:
-#line 1802 "grammar.y"
+  case 112:
+#line 1810 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(1) - (3)].expression), EXPRESSION_TYPE_INTEGER, "%");
         CHECK_TYPE((yyvsp[(3) - (3)].expression), EXPRESSION_TYPE_INTEGER, "%");
@@ -3589,8 +3600,8 @@ yyreduce:
       }
     break;
 
-  case 112:
-#line 1820 "grammar.y"
+  case 113:
+#line 1828 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(1) - (3)].expression), EXPRESSION_TYPE_INTEGER, "^");
         CHECK_TYPE((yyvsp[(3) - (3)].expression), EXPRESSION_TYPE_INTEGER, "^");
@@ -3602,8 +3613,8 @@ yyreduce:
       }
     break;
 
-  case 113:
-#line 1830 "grammar.y"
+  case 114:
+#line 1838 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(1) - (3)].expression), EXPRESSION_TYPE_INTEGER, "^");
         CHECK_TYPE((yyvsp[(3) - (3)].expression), EXPRESSION_TYPE_INTEGER, "^");
@@ -3615,8 +3626,8 @@ yyreduce:
       }
     break;
 
-  case 114:
-#line 1840 "grammar.y"
+  case 115:
+#line 1848 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(1) - (3)].expression), EXPRESSION_TYPE_INTEGER, "|");
         CHECK_TYPE((yyvsp[(3) - (3)].expression), EXPRESSION_TYPE_INTEGER, "|");
@@ -3628,8 +3639,8 @@ yyreduce:
       }
     break;
 
-  case 115:
-#line 1850 "grammar.y"
+  case 116:
+#line 1858 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(2) - (2)].expression), EXPRESSION_TYPE_INTEGER, "~");
 
@@ -3641,8 +3652,8 @@ yyreduce:
       }
     break;
 
-  case 116:
-#line 1860 "grammar.y"
+  case 117:
+#line 1868 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(1) - (3)].expression), EXPRESSION_TYPE_INTEGER, "<<");
         CHECK_TYPE((yyvsp[(3) - (3)].expression), EXPRESSION_TYPE_INTEGER, "<<");
@@ -3654,8 +3665,8 @@ yyreduce:
       }
     break;
 
-  case 117:
-#line 1870 "grammar.y"
+  case 118:
+#line 1878 "grammar.y"
     {
         CHECK_TYPE((yyvsp[(1) - (3)].expression), EXPRESSION_TYPE_INTEGER, ">>");
         CHECK_TYPE((yyvsp[(3) - (3)].expression), EXPRESSION_TYPE_INTEGER, ">>");
@@ -3667,8 +3678,8 @@ yyreduce:
       }
     break;
 
-  case 118:
-#line 1880 "grammar.y"
+  case 119:
+#line 1888 "grammar.y"
     {
         (yyval.expression) = (yyvsp[(1) - (1)].expression);
       }
@@ -3676,7 +3687,7 @@ yyreduce:
 
 
 /* Line 1267 of yacc.c.  */
-#line 3680 "grammar.c"
+#line 3691 "grammar.c"
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -3890,6 +3901,6 @@ yyreturn:
 }
 
 
-#line 1885 "grammar.y"
+#line 1893 "grammar.y"
 
 
diff --git a/libyara/grammar.y b/libyara/grammar.y
index 96a6cb1..6cbfe83 100644
--- a/libyara/grammar.y
+++ b/libyara/grammar.y
@@ -220,18 +220,26 @@ import
 
 
 rule
-    : rule_modifiers _RULE_ _IDENTIFIER_ tags '{' meta strings
+    : rule_modifiers _RULE_ _IDENTIFIER_
       {
         YR_RULE* rule = yr_parser_reduce_rule_declaration_phase_1(
-            yyscanner, (int32_t) $1, $3, $4, $7, $6);
+            yyscanner, (int32_t) $1, $3);
 
         ERROR_IF(rule == NULL);
 
         $<rule>$ = rule;
       }
+      tags '{' meta strings
+      {
+        YR_RULE* rule = $<rule>6; // rule created in phase 1
+
+        rule->tags = $5;
+        rule->metas = $7;
+        rule->strings = $8;
+      }
       condition '}'
       {
-        YR_RULE* rule = $<rule>8; // rule created in phase 1
+        YR_RULE* rule = $<rule>6; // rule created in phase 1
 
         compiler->last_result = yr_parser_reduce_rule_declaration_phase_2(
             yyscanner, rule);
diff --git a/libyara/hash.c b/libyara/hash.c
index 874e300..3f8285b 100644
--- a/libyara/hash.c
+++ b/libyara/hash.c
@@ -109,7 +109,8 @@ YR_API int yr_hash_table_create(
   return ERROR_SUCCESS;
 }
 
-YR_API void yr_hash_table_destroy(
+
+YR_API void yr_hash_table_clean(
     YR_HASH_TABLE* table,
     YR_HASH_TABLE_FREE_VALUE_FUNC free_value)
 {
@@ -140,8 +141,17 @@ YR_API void yr_hash_table_destroy(
 
       entry = next_entry;
     }
+
+    table->buckets[i] = NULL;
   }
+}
+
 
+YR_API void yr_hash_table_destroy(
+    YR_HASH_TABLE* table,
+    YR_HASH_TABLE_FREE_VALUE_FUNC free_value)
+{
+  yr_hash_table_clean(table, free_value);
   yr_free(table);
 }
 
diff --git a/libyara/include/yara/compiler.h b/libyara/include/yara/compiler.h
index d70d0b2..237309a 100644
--- a/libyara/include/yara/compiler.h
+++ b/libyara/include/yara/compiler.h
@@ -70,6 +70,7 @@ typedef struct _YR_COMPILER
   YR_AC_AUTOMATON*  automaton;
   YR_HASH_TABLE*    rules_table;
   YR_HASH_TABLE*    objects_table;
+  YR_HASH_TABLE*    strings_table;
   YR_NAMESPACE*     current_namespace;
   YR_RULE*          current_rule;
 
diff --git a/libyara/include/yara/hash.h b/libyara/include/yara/hash.h
index 2474203..ce74a18 100644
--- a/libyara/include/yara/hash.h
+++ b/libyara/include/yara/hash.h
@@ -47,6 +47,11 @@ YR_API int yr_hash_table_create(
     YR_HASH_TABLE** table);
 
 
+YR_API void yr_hash_table_clean(
+    YR_HASH_TABLE* table,
+    YR_HASH_TABLE_FREE_VALUE_FUNC free_value);
+
+
 YR_API void yr_hash_table_destroy(
     YR_HASH_TABLE* table,
     YR_HASH_TABLE_FREE_VALUE_FUNC free_value);
diff --git a/libyara/include/yara/parser.h b/libyara/include/yara/parser.h
index 584e1c0..3208d5f 100644
--- a/libyara/include/yara/parser.h
+++ b/libyara/include/yara/parser.h
@@ -70,10 +70,7 @@ int yr_parser_lookup_loop_variable(
 YR_RULE* yr_parser_reduce_rule_declaration_phase_1(
     yyscan_t yyscanner,
     int32_t flags,
-    const char* identifier,
-    char* tags,
-    YR_STRING* strings,
-    YR_META* metas);
+    const char* identifier);
 
 
 int yr_parser_reduce_rule_declaration_phase_2(
diff --git a/libyara/lexer.c b/libyara/lexer.c
index 7e516b2..201ae61 100644
--- a/libyara/lexer.c
+++ b/libyara/lexer.c
@@ -1533,7 +1533,7 @@ YY_RULE_SETUP
 
   if (strlen(yytext) > 128)
   {
-    yyerror(yyscanner, compiler, "indentifier too long");
+    yyerror(yyscanner, compiler, "identifier too long");
   }
 
   yylval->c_string = yr_strdup(yytext);
diff --git a/libyara/parser.c b/libyara/parser.c
index 652b806..e533cc1 100644
--- a/libyara/parser.c
+++ b/libyara/parser.c
@@ -465,6 +465,23 @@ YR_STRING* yr_parser_reduce_string_declaration(
 
   RE_ERROR re_error;
 
+  // Determine if a string with the same identifier was already defined
+  // by searching for the identifier in string_table.
+
+  string = yr_hash_table_lookup(
+      compiler->strings_table,
+      identifier,
+      NULL);
+
+  if (string != NULL)
+  {
+    compiler->last_result = ERROR_DUPLICATED_STRING_IDENTIFIER;
+    yr_compiler_set_error_extra_info(compiler, identifier);
+    goto _exit;
+  }
+
+  // Empty strings are now allowed
+
   if (str->length == 0)
   {
     compiler->last_result = ERROR_EMPTY_STRING;
@@ -653,6 +670,15 @@ YR_STRING* yr_parser_reduce_string_declaration(
       goto _exit;
   }
 
+  compiler->last_result = yr_hash_table_add(
+      compiler->strings_table,
+      identifier,
+      NULL,
+      string);
+
+  if (compiler->last_result != ERROR_SUCCESS)
+    goto _exit;
+
   if (min_atom_quality < 3 && compiler->callback != NULL)
   {
     snprintf(
@@ -680,10 +706,7 @@ _exit:
 YR_RULE* yr_parser_reduce_rule_declaration_phase_1(
     yyscan_t yyscanner,
     int32_t flags,
-    const char* identifier,
-    char* tags,
-    YR_STRING* strings,
-    YR_META* metas)
+    const char* identifier)
 {
   YR_COMPILER* compiler = yyget_extra(yyscanner);
   YR_RULE* rule = NULL;
@@ -720,9 +743,6 @@ YR_RULE* yr_parser_reduce_rule_declaration_phase_1(
     return NULL;
 
   rule->g_flags = flags;
-  rule->tags = tags;
-  rule->strings = strings;
-  rule->metas = metas;
   rule->ns = compiler->current_namespace;
 
   #ifdef PROFILING_ENABLED
@@ -751,8 +771,10 @@ YR_RULE* yr_parser_reduce_rule_declaration_phase_1(
         compiler->current_namespace->name,
         (void*) rule);
 
-  compiler->current_rule = rule;
+  // Clean strings_table as we are starting to parse a new rule.
+  yr_hash_table_clean(compiler->strings_table, NULL);
 
+  compiler->current_rule = rule;
   return rule;
 }
 
@@ -797,7 +819,6 @@ int yr_parser_reduce_rule_declaration_phase_2(
 }
 
 
-
 int yr_parser_reduce_string_identifier(
     yyscan_t yyscanner,
     const char* identifier,

-- 
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