[Forensics-changes] [yara] 297/415: Improve dmalloc integration and fix some memory leaks
Hilko Bengen
bengen at moszumanska.debian.org
Thu Apr 3 05:43:16 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch debian
in repository yara.
commit 93c173928a10cdad727bb0b65f0c7f5f78e0f931
Author: Victor M. Alvarez <plusvic at gmail.com>
Date: Sat Dec 7 13:33:44 2013 +0100
Improve dmalloc integration and fix some memory leaks
---
libyara/grammar.c | 260 ++++++++++++++++++++++++++------------------------
libyara/grammar.h | 2 +-
libyara/grammar.y | 6 ++
libyara/hex_grammar.c | 84 ++++++++++++----
libyara/hex_grammar.h | 2 +-
libyara/hex_grammar.y | 27 ++++++
libyara/hex_lexer.c | 40 ++++----
libyara/hex_lexer.l | 5 +
libyara/lexer.c | 176 +++++++++++++++++-----------------
libyara/lexer.l | 5 +
libyara/mem.h | 19 +++-
libyara/re.h | 10 ++
libyara/re_grammar.c | 117 ++++++++++++++++-------
libyara/re_grammar.h | 2 +-
libyara/re_grammar.y | 34 ++++++-
libyara/re_lexer.c | 79 ++++++++-------
libyara/re_lexer.l | 6 ++
yara.c | 14 +++
yarac.c | 10 +-
19 files changed, 566 insertions(+), 332 deletions(-)
diff --git a/libyara/grammar.c b/libyara/grammar.c
index 4dea912..fbac5ea 100644
--- a/libyara/grammar.c
+++ b/libyara/grammar.c
@@ -223,6 +223,12 @@
#include "utils.h"
#include "yara.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
#define YYERROR_VERBOSE
#define INTEGER_SET_ENUMERATION 1
@@ -257,7 +263,7 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 148 "grammar.y"
+#line 154 "grammar.y"
{
SIZED_STRING* sized_string;
char* c_string;
@@ -266,7 +272,7 @@ typedef union YYSTYPE
YR_META* meta;
}
/* Line 193 of yacc.c. */
-#line 270 "grammar.c"
+#line 276 "grammar.c"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
@@ -279,7 +285,7 @@ typedef union YYSTYPE
/* Line 216 of yacc.c. */
-#line 283 "grammar.c"
+#line 289 "grammar.c"
#ifdef short
# undef short
@@ -613,18 +619,18 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 159, 159, 160, 161, 162, 166, 183, 184, 212,
- 216, 244, 248, 249, 253, 254, 258, 259, 274, 284,
- 318, 319, 323, 339, 352, 365, 381, 382, 386, 400,
- 399, 417, 433, 434, 438, 439, 440, 441, 445, 446,
- 450, 454, 484, 522, 526, 537, 548, 552, 563, 569,
- 606, 568, 705, 704, 773, 777, 780, 784, 788, 792,
- 796, 800, 804, 808, 812, 816, 823, 842, 856, 857,
- 861, 865, 866, 870, 869, 874, 881, 882, 885, 890,
- 897, 898, 902, 909, 910, 914, 918, 922, 926, 930,
- 934, 938, 942, 946, 957, 968, 982, 1009, 1013, 1017,
- 1021, 1025, 1029, 1033, 1037, 1041, 1045, 1049, 1055, 1056,
- 1057
+ 0, 165, 165, 166, 167, 168, 172, 189, 190, 218,
+ 222, 250, 254, 255, 259, 260, 264, 265, 280, 290,
+ 324, 325, 329, 345, 358, 371, 387, 388, 392, 406,
+ 405, 423, 439, 440, 444, 445, 446, 447, 451, 452,
+ 456, 460, 490, 528, 532, 543, 554, 558, 569, 575,
+ 612, 574, 711, 710, 779, 783, 786, 790, 794, 798,
+ 802, 806, 810, 814, 818, 822, 829, 848, 862, 863,
+ 867, 871, 872, 876, 875, 880, 887, 888, 891, 896,
+ 903, 904, 908, 915, 916, 920, 924, 928, 932, 936,
+ 940, 944, 948, 952, 963, 974, 988, 1015, 1019, 1023,
+ 1027, 1031, 1035, 1039, 1043, 1047, 1051, 1055, 1061, 1062,
+ 1063
};
#endif
@@ -1421,49 +1427,49 @@ yydestruct (yymsg, yytype, yyvaluep, yyscanner)
switch (yytype)
{
case 10: /* "_IDENTIFIER_" */
-#line 138 "grammar.y"
+#line 144 "grammar.y"
{ yr_free((yyvaluep->c_string)); };
-#line 1427 "grammar.c"
+#line 1433 "grammar.c"
break;
case 11: /* "_STRING_IDENTIFIER_" */
-#line 139 "grammar.y"
+#line 145 "grammar.y"
{ yr_free((yyvaluep->c_string)); };
-#line 1432 "grammar.c"
+#line 1438 "grammar.c"
break;
case 12: /* "_STRING_COUNT_" */
-#line 140 "grammar.y"
+#line 146 "grammar.y"
{ yr_free((yyvaluep->c_string)); };
-#line 1437 "grammar.c"
+#line 1443 "grammar.c"
break;
case 13: /* "_STRING_OFFSET_" */
-#line 141 "grammar.y"
+#line 147 "grammar.y"
{ yr_free((yyvaluep->c_string)); };
-#line 1442 "grammar.c"
+#line 1448 "grammar.c"
break;
case 14: /* "_STRING_IDENTIFIER_WITH_WILDCARD_" */
-#line 142 "grammar.y"
+#line 148 "grammar.y"
{ yr_free((yyvaluep->c_string)); };
-#line 1447 "grammar.c"
+#line 1453 "grammar.c"
break;
case 15: /* "_ANONYMOUS_STRING_" */
-#line 143 "grammar.y"
+#line 149 "grammar.y"
{ yr_free((yyvaluep->c_string)); };
-#line 1452 "grammar.c"
+#line 1458 "grammar.c"
break;
case 18: /* "_TEXTSTRING_" */
-#line 144 "grammar.y"
+#line 150 "grammar.y"
{ yr_free((yyvaluep->sized_string)); };
-#line 1457 "grammar.c"
+#line 1463 "grammar.c"
break;
case 19: /* "_HEXSTRING_" */
-#line 145 "grammar.y"
+#line 151 "grammar.y"
{ yr_free((yyvaluep->sized_string)); };
-#line 1462 "grammar.c"
+#line 1468 "grammar.c"
break;
case 20: /* "_REGEXP_" */
-#line 146 "grammar.y"
+#line 152 "grammar.y"
{ yr_free((yyvaluep->sized_string)); };
-#line 1467 "grammar.c"
+#line 1473 "grammar.c"
break;
default:
@@ -1772,7 +1778,7 @@ yyreduce:
switch (yyn)
{
case 6:
-#line 167 "grammar.y"
+#line 173 "grammar.y"
{
int result = yr_parser_reduce_rule_declaration(
yyscanner,
@@ -1789,12 +1795,12 @@ yyreduce:
break;
case 7:
-#line 183 "grammar.y"
+#line 189 "grammar.y"
{ (yyval.meta) = NULL; }
break;
case 8:
-#line 185 "grammar.y"
+#line 191 "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
@@ -1821,7 +1827,7 @@ yyreduce:
break;
case 9:
-#line 212 "grammar.y"
+#line 218 "grammar.y"
{
(yyval.string) = NULL;
yyget_extra(yyscanner)->current_rule_strings = (yyval.string);
@@ -1829,7 +1835,7 @@ yyreduce:
break;
case 10:
-#line 217 "grammar.y"
+#line 223 "grammar.y"
{
// Each rule have a list of strings, consisting in a sequence
// of YR_STRING structures. The last YR_STRING structure does not
@@ -1857,32 +1863,32 @@ yyreduce:
break;
case 12:
-#line 248 "grammar.y"
+#line 254 "grammar.y"
{ (yyval.integer) = 0; }
break;
case 13:
-#line 249 "grammar.y"
+#line 255 "grammar.y"
{ (yyval.integer) = (yyvsp[(1) - (2)].integer) | (yyvsp[(2) - (2)].integer); }
break;
case 14:
-#line 253 "grammar.y"
+#line 259 "grammar.y"
{ (yyval.integer) = RULE_GFLAGS_PRIVATE; }
break;
case 15:
-#line 254 "grammar.y"
+#line 260 "grammar.y"
{ (yyval.integer) = RULE_GFLAGS_GLOBAL; }
break;
case 16:
-#line 258 "grammar.y"
+#line 264 "grammar.y"
{ (yyval.c_string) = NULL; }
break;
case 17:
-#line 260 "grammar.y"
+#line 266 "grammar.y"
{
// Tags list is represented in the arena as a sequence
// of null-terminated strings, the sequence ends with an
@@ -1897,7 +1903,7 @@ yyreduce:
break;
case 18:
-#line 275 "grammar.y"
+#line 281 "grammar.y"
{
char* identifier;
@@ -1910,7 +1916,7 @@ yyreduce:
break;
case 19:
-#line 285 "grammar.y"
+#line 291 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
char* tag_name = (yyvsp[(1) - (2)].c_string);
@@ -1945,17 +1951,17 @@ yyreduce:
break;
case 20:
-#line 318 "grammar.y"
+#line 324 "grammar.y"
{ (yyval.meta) = (yyvsp[(1) - (1)].meta); }
break;
case 21:
-#line 319 "grammar.y"
+#line 325 "grammar.y"
{ (yyval.meta) = (yyvsp[(1) - (2)].meta); }
break;
case 22:
-#line 324 "grammar.y"
+#line 330 "grammar.y"
{
SIZED_STRING* sized_string = (yyvsp[(3) - (3)].sized_string);
@@ -1974,7 +1980,7 @@ yyreduce:
break;
case 23:
-#line 340 "grammar.y"
+#line 346 "grammar.y"
{
(yyval.meta) = yr_parser_reduce_meta_declaration(
yyscanner,
@@ -1990,7 +1996,7 @@ yyreduce:
break;
case 24:
-#line 353 "grammar.y"
+#line 359 "grammar.y"
{
(yyval.meta) = yr_parser_reduce_meta_declaration(
yyscanner,
@@ -2006,7 +2012,7 @@ yyreduce:
break;
case 25:
-#line 366 "grammar.y"
+#line 372 "grammar.y"
{
(yyval.meta) = yr_parser_reduce_meta_declaration(
yyscanner,
@@ -2022,17 +2028,17 @@ yyreduce:
break;
case 26:
-#line 381 "grammar.y"
+#line 387 "grammar.y"
{ (yyval.string) = (yyvsp[(1) - (1)].string); }
break;
case 27:
-#line 382 "grammar.y"
+#line 388 "grammar.y"
{ (yyval.string) = (yyvsp[(1) - (2)].string); }
break;
case 28:
-#line 387 "grammar.y"
+#line 393 "grammar.y"
{
(yyval.string) = yr_parser_reduce_string_declaration(
yyscanner,
@@ -2048,7 +2054,7 @@ yyreduce:
break;
case 29:
-#line 400 "grammar.y"
+#line 406 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
compiler->error_line = yyget_lineno(yyscanner);
@@ -2056,7 +2062,7 @@ yyreduce:
break;
case 30:
-#line 405 "grammar.y"
+#line 411 "grammar.y"
{
(yyval.string) = yr_parser_reduce_string_declaration(
yyscanner,
@@ -2072,7 +2078,7 @@ yyreduce:
break;
case 31:
-#line 418 "grammar.y"
+#line 424 "grammar.y"
{
(yyval.string) = yr_parser_reduce_string_declaration(
yyscanner,
@@ -2088,51 +2094,51 @@ yyreduce:
break;
case 32:
-#line 433 "grammar.y"
+#line 439 "grammar.y"
{ (yyval.integer) = 0; }
break;
case 33:
-#line 434 "grammar.y"
+#line 440 "grammar.y"
{ (yyval.integer) = (yyvsp[(1) - (2)].integer) | (yyvsp[(2) - (2)].integer); }
break;
case 34:
-#line 438 "grammar.y"
+#line 444 "grammar.y"
{ (yyval.integer) = STRING_GFLAGS_WIDE; }
break;
case 35:
-#line 439 "grammar.y"
+#line 445 "grammar.y"
{ (yyval.integer) = STRING_GFLAGS_ASCII; }
break;
case 36:
-#line 440 "grammar.y"
+#line 446 "grammar.y"
{ (yyval.integer) = STRING_GFLAGS_NO_CASE; }
break;
case 37:
-#line 441 "grammar.y"
+#line 447 "grammar.y"
{ (yyval.integer) = STRING_GFLAGS_FULL_WORD; }
break;
case 39:
-#line 447 "grammar.y"
+#line 453 "grammar.y"
{
yr_parser_emit_with_arg(yyscanner, PUSH, 1, NULL);
}
break;
case 40:
-#line 451 "grammar.y"
+#line 457 "grammar.y"
{
yr_parser_emit_with_arg(yyscanner, PUSH, 0, NULL);
}
break;
case 41:
-#line 455 "grammar.y"
+#line 461 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
YR_RULE* rule;
@@ -2165,7 +2171,7 @@ yyreduce:
break;
case 42:
-#line 485 "grammar.y"
+#line 491 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
SIZED_STRING* sized_string = (yyvsp[(3) - (3)].sized_string);
@@ -2206,14 +2212,14 @@ yyreduce:
break;
case 43:
-#line 523 "grammar.y"
+#line 529 "grammar.y"
{
yr_parser_emit(yyscanner, CONTAINS, NULL);
}
break;
case 44:
-#line 527 "grammar.y"
+#line 533 "grammar.y"
{
int result = yr_parser_reduce_string_identifier(
yyscanner,
@@ -2227,7 +2233,7 @@ yyreduce:
break;
case 45:
-#line 538 "grammar.y"
+#line 544 "grammar.y"
{
int result = yr_parser_reduce_string_identifier(
yyscanner,
@@ -2241,14 +2247,14 @@ yyreduce:
break;
case 46:
-#line 549 "grammar.y"
+#line 555 "grammar.y"
{
yr_free((yyvsp[(1) - (4)].c_string));
}
break;
case 47:
-#line 553 "grammar.y"
+#line 559 "grammar.y"
{
int result = yr_parser_reduce_string_identifier(
yyscanner,
@@ -2262,7 +2268,7 @@ yyreduce:
break;
case 48:
-#line 564 "grammar.y"
+#line 570 "grammar.y"
{
yr_free((yyvsp[(1) - (6)].c_string));
yr_free((yyvsp[(5) - (6)].sized_string));
@@ -2270,7 +2276,7 @@ yyreduce:
break;
case 49:
-#line 569 "grammar.y"
+#line 575 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
int result = ERROR_SUCCESS;
@@ -2310,7 +2316,7 @@ yyreduce:
break;
case 50:
-#line 606 "grammar.y"
+#line 612 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
int mem_offset = LOOP_LOCAL_VARS * compiler->loop_depth;
@@ -2347,7 +2353,7 @@ yyreduce:
break;
case 51:
-#line 640 "grammar.y"
+#line 646 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
int mem_offset;
@@ -2415,7 +2421,7 @@ yyreduce:
break;
case 52:
-#line 705 "grammar.y"
+#line 711 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
int mem_offset = LOOP_LOCAL_VARS * compiler->loop_depth;
@@ -2443,7 +2449,7 @@ yyreduce:
break;
case 53:
-#line 730 "grammar.y"
+#line 736 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
int mem_offset;
@@ -2490,90 +2496,90 @@ yyreduce:
break;
case 54:
-#line 774 "grammar.y"
+#line 780 "grammar.y"
{
yr_parser_emit(yyscanner, OF, NULL);
}
break;
case 55:
-#line 778 "grammar.y"
+#line 784 "grammar.y"
{
}
break;
case 56:
-#line 781 "grammar.y"
+#line 787 "grammar.y"
{
yr_parser_emit(yyscanner, NOT, NULL);
}
break;
case 57:
-#line 785 "grammar.y"
+#line 791 "grammar.y"
{
yr_parser_emit(yyscanner, AND, NULL);
}
break;
case 58:
-#line 789 "grammar.y"
+#line 795 "grammar.y"
{
yr_parser_emit(yyscanner, OR, NULL);
}
break;
case 59:
-#line 793 "grammar.y"
+#line 799 "grammar.y"
{
yr_parser_emit(yyscanner, LT, NULL);
}
break;
case 60:
-#line 797 "grammar.y"
+#line 803 "grammar.y"
{
yr_parser_emit(yyscanner, GT, NULL);
}
break;
case 61:
-#line 801 "grammar.y"
+#line 807 "grammar.y"
{
yr_parser_emit(yyscanner, LE, NULL);
}
break;
case 62:
-#line 805 "grammar.y"
+#line 811 "grammar.y"
{
yr_parser_emit(yyscanner, GE, NULL);
}
break;
case 63:
-#line 809 "grammar.y"
+#line 815 "grammar.y"
{
yr_parser_emit(yyscanner, EQ, NULL);
}
break;
case 64:
-#line 813 "grammar.y"
+#line 819 "grammar.y"
{
yr_parser_emit(yyscanner, EQ, NULL);
}
break;
case 65:
-#line 817 "grammar.y"
+#line 823 "grammar.y"
{
yr_parser_emit(yyscanner, NEQ, NULL);
}
break;
case 66:
-#line 824 "grammar.y"
+#line 830 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
SIZED_STRING* sized_string = (yyvsp[(1) - (1)].sized_string);
@@ -2595,7 +2601,7 @@ yyreduce:
break;
case 67:
-#line 843 "grammar.y"
+#line 849 "grammar.y"
{
int result = yr_parser_reduce_external(
yyscanner,
@@ -2609,24 +2615,24 @@ yyreduce:
break;
case 68:
-#line 856 "grammar.y"
+#line 862 "grammar.y"
{ (yyval.integer) = INTEGER_SET_ENUMERATION; }
break;
case 69:
-#line 857 "grammar.y"
+#line 863 "grammar.y"
{ (yyval.integer) = INTEGER_SET_RANGE; }
break;
case 73:
-#line 870 "grammar.y"
+#line 876 "grammar.y"
{
yr_parser_emit_with_arg(yyscanner, PUSH, UNDEFINED, NULL);
}
break;
case 75:
-#line 875 "grammar.y"
+#line 881 "grammar.y"
{
yr_parser_emit_with_arg(yyscanner, PUSH, UNDEFINED, NULL);
yr_parser_emit_pushes_for_strings(yyscanner, "$*");
@@ -2634,7 +2640,7 @@ yyreduce:
break;
case 78:
-#line 886 "grammar.y"
+#line 892 "grammar.y"
{
yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[(1) - (1)].c_string));
yr_free((yyvsp[(1) - (1)].c_string));
@@ -2642,7 +2648,7 @@ yyreduce:
break;
case 79:
-#line 891 "grammar.y"
+#line 897 "grammar.y"
{
yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[(1) - (1)].c_string));
yr_free((yyvsp[(1) - (1)].c_string));
@@ -2650,84 +2656,84 @@ yyreduce:
break;
case 81:
-#line 899 "grammar.y"
+#line 905 "grammar.y"
{
yr_parser_emit_with_arg(yyscanner, PUSH, UNDEFINED, NULL);
}
break;
case 82:
-#line 903 "grammar.y"
+#line 909 "grammar.y"
{
yr_parser_emit_with_arg(yyscanner, PUSH, 1, NULL);
}
break;
case 84:
-#line 911 "grammar.y"
+#line 917 "grammar.y"
{
yr_parser_emit(yyscanner, SIZE, NULL);
}
break;
case 85:
-#line 915 "grammar.y"
+#line 921 "grammar.y"
{
yr_parser_emit(yyscanner, ENTRYPOINT, NULL);
}
break;
case 86:
-#line 919 "grammar.y"
+#line 925 "grammar.y"
{
yr_parser_emit(yyscanner, INT8, NULL);
}
break;
case 87:
-#line 923 "grammar.y"
+#line 929 "grammar.y"
{
yr_parser_emit(yyscanner, INT16, NULL);
}
break;
case 88:
-#line 927 "grammar.y"
+#line 933 "grammar.y"
{
yr_parser_emit(yyscanner, INT32, NULL);
}
break;
case 89:
-#line 931 "grammar.y"
+#line 937 "grammar.y"
{
yr_parser_emit(yyscanner, UINT8, NULL);
}
break;
case 90:
-#line 935 "grammar.y"
+#line 941 "grammar.y"
{
yr_parser_emit(yyscanner, UINT16, NULL);
}
break;
case 91:
-#line 939 "grammar.y"
+#line 945 "grammar.y"
{
yr_parser_emit(yyscanner, UINT32, NULL);
}
break;
case 92:
-#line 943 "grammar.y"
+#line 949 "grammar.y"
{
yr_parser_emit_with_arg(yyscanner, PUSH, (yyvsp[(1) - (1)].integer), NULL);
}
break;
case 93:
-#line 947 "grammar.y"
+#line 953 "grammar.y"
{
int result = yr_parser_reduce_string_identifier(
yyscanner,
@@ -2741,7 +2747,7 @@ yyreduce:
break;
case 94:
-#line 958 "grammar.y"
+#line 964 "grammar.y"
{
int result = yr_parser_reduce_string_identifier(
yyscanner,
@@ -2755,7 +2761,7 @@ yyreduce:
break;
case 95:
-#line 969 "grammar.y"
+#line 975 "grammar.y"
{
int result = yr_parser_emit_with_arg(yyscanner, PUSH, 1, NULL);
@@ -2772,7 +2778,7 @@ yyreduce:
break;
case 96:
-#line 983 "grammar.y"
+#line 989 "grammar.y"
{
YR_COMPILER* compiler = yyget_extra(yyscanner);
int var_index;
@@ -2802,77 +2808,77 @@ yyreduce:
break;
case 97:
-#line 1010 "grammar.y"
+#line 1016 "grammar.y"
{
yr_parser_emit(yyscanner, ADD, NULL);
}
break;
case 98:
-#line 1014 "grammar.y"
+#line 1020 "grammar.y"
{
yr_parser_emit(yyscanner, SUB, NULL);
}
break;
case 99:
-#line 1018 "grammar.y"
+#line 1024 "grammar.y"
{
yr_parser_emit(yyscanner, MUL, NULL);
}
break;
case 100:
-#line 1022 "grammar.y"
+#line 1028 "grammar.y"
{
yr_parser_emit(yyscanner, DIV, NULL);
}
break;
case 101:
-#line 1026 "grammar.y"
+#line 1032 "grammar.y"
{
yr_parser_emit(yyscanner, MOD, NULL);
}
break;
case 102:
-#line 1030 "grammar.y"
+#line 1036 "grammar.y"
{
yr_parser_emit(yyscanner, XOR, NULL);
}
break;
case 103:
-#line 1034 "grammar.y"
+#line 1040 "grammar.y"
{
yr_parser_emit(yyscanner, AND, NULL);
}
break;
case 104:
-#line 1038 "grammar.y"
+#line 1044 "grammar.y"
{
yr_parser_emit(yyscanner, OR, NULL);
}
break;
case 105:
-#line 1042 "grammar.y"
+#line 1048 "grammar.y"
{
yr_parser_emit(yyscanner, NEG, NULL);
}
break;
case 106:
-#line 1046 "grammar.y"
+#line 1052 "grammar.y"
{
yr_parser_emit(yyscanner, SHL, NULL);
}
break;
case 107:
-#line 1050 "grammar.y"
+#line 1056 "grammar.y"
{
yr_parser_emit(yyscanner, SHR, NULL);
}
@@ -2880,7 +2886,7 @@ yyreduce:
/* Line 1267 of yacc.c. */
-#line 2884 "grammar.c"
+#line 2890 "grammar.c"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -3094,7 +3100,7 @@ yyreturn:
}
-#line 1060 "grammar.y"
+#line 1066 "grammar.y"
diff --git a/libyara/grammar.h b/libyara/grammar.h
index 9f9cf2f..421e74f 100644
--- a/libyara/grammar.h
+++ b/libyara/grammar.h
@@ -170,7 +170,7 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 148 "grammar.y"
+#line 154 "grammar.y"
{
SIZED_STRING* sized_string;
char* c_string;
diff --git a/libyara/grammar.y b/libyara/grammar.y
index ff2f88f..0aa732a 100644
--- a/libyara/grammar.y
+++ b/libyara/grammar.y
@@ -32,6 +32,12 @@ limitations under the License.
#include "utils.h"
#include "yara.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
#define YYERROR_VERBOSE
#define INTEGER_SET_ENUMERATION 1
diff --git a/libyara/hex_grammar.c b/libyara/hex_grammar.c
index bba5dc6..9b51054 100644
--- a/libyara/hex_grammar.c
+++ b/libyara/hex_grammar.c
@@ -98,6 +98,12 @@
#include "re.h"
#include "yara.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
#define YYERROR_VERBOSE
#define YYDEBUG 0
@@ -120,6 +126,12 @@ yydebug = 1;
YYABORT; \
} \
+#define DESTROY_NODE_IF(x, node) \
+ if (x) \
+ { \
+ yr_re_node_destroy(node); \
+ } \
+
/* Enabling traces. */
@@ -142,13 +154,13 @@ yydebug = 1;
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 61 "hex_grammar.y"
+#line 73 "hex_grammar.y"
{
int integer;
RE_NODE *re_node;
}
/* Line 193 of yacc.c. */
-#line 152 "hex_grammar.c"
+#line 164 "hex_grammar.c"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
@@ -161,7 +173,7 @@ typedef union YYSTYPE
/* Line 216 of yacc.c. */
-#line 165 "hex_grammar.c"
+#line 177 "hex_grammar.c"
#ifdef short
# undef short
@@ -447,8 +459,8 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
- 0, 74, 74, 82, 86, 94, 98, 102, 110, 123,
- 147, 151, 162, 186
+ 0, 92, 92, 100, 104, 115, 119, 123, 131, 146,
+ 172, 176, 189, 213
};
#endif
@@ -1064,6 +1076,31 @@ yydestruct (yymsg, yytype, yyvaluep, yyscanner, lex_env)
switch (yytype)
{
+ case 16: /* "tokens" */
+#line 84 "hex_grammar.y"
+ { yr_re_node_destroy((yyvaluep->re_node)); };
+#line 1083 "hex_grammar.c"
+ break;
+ case 17: /* "token" */
+#line 85 "hex_grammar.y"
+ { yr_re_node_destroy((yyvaluep->re_node)); };
+#line 1088 "hex_grammar.c"
+ break;
+ case 18: /* "range" */
+#line 88 "hex_grammar.y"
+ { yr_re_node_destroy((yyvaluep->re_node)); };
+#line 1093 "hex_grammar.c"
+ break;
+ case 19: /* "alternatives" */
+#line 87 "hex_grammar.y"
+ { yr_re_node_destroy((yyvaluep->re_node)); };
+#line 1098 "hex_grammar.c"
+ break;
+ case 20: /* "byte" */
+#line 86 "hex_grammar.y"
+ { yr_re_node_destroy((yyvaluep->re_node)); };
+#line 1103 "hex_grammar.c"
+ break;
default:
break;
@@ -1372,7 +1409,7 @@ yyreduce:
switch (yyn)
{
case 2:
-#line 75 "hex_grammar.y"
+#line 93 "hex_grammar.y"
{
RE* re = yyget_extra(yyscanner);
re->root_node = (yyvsp[(2) - (3)].re_node);
@@ -1380,36 +1417,39 @@ yyreduce:
break;
case 3:
-#line 83 "hex_grammar.y"
+#line 101 "hex_grammar.y"
{
(yyval.re_node) = (yyvsp[(1) - (1)].re_node);
}
break;
case 4:
-#line 87 "hex_grammar.y"
+#line 105 "hex_grammar.y"
{
(yyval.re_node) = yr_re_node_create(RE_NODE_CONCAT, (yyvsp[(1) - (2)].re_node), (yyvsp[(2) - (2)].re_node));
+
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (2)].re_node));
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(2) - (2)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
}
break;
case 5:
-#line 95 "hex_grammar.y"
+#line 116 "hex_grammar.y"
{
(yyval.re_node) = (yyvsp[(1) - (1)].re_node);
}
break;
case 6:
-#line 99 "hex_grammar.y"
+#line 120 "hex_grammar.y"
{
(yyval.re_node) = (yyvsp[(2) - (3)].re_node);
}
break;
case 7:
-#line 103 "hex_grammar.y"
+#line 124 "hex_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = (yyvsp[(2) - (3)].re_node);
@@ -1417,12 +1457,14 @@ yyreduce:
break;
case 8:
-#line 111 "hex_grammar.y"
+#line 132 "hex_grammar.y"
{
RE_NODE* re_any;
re_any = yr_re_node_create(RE_NODE_ANY, NULL, NULL);
+ ERROR_IF(re_any == NULL, ERROR_INSUFICIENT_MEMORY);
+
(yyval.re_node) = yr_re_node_create(RE_NODE_RANGE, re_any, NULL);
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
@@ -1433,7 +1475,7 @@ yyreduce:
break;
case 9:
-#line 124 "hex_grammar.y"
+#line 147 "hex_grammar.y"
{
RE_NODE* re_any;
@@ -1447,6 +1489,8 @@ yyreduce:
re_any = yr_re_node_create(RE_NODE_ANY, NULL, NULL);
+ ERROR_IF(re_any == NULL, ERROR_INSUFICIENT_MEMORY);
+
(yyval.re_node) = yr_re_node_create(RE_NODE_RANGE, re_any, NULL);
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
@@ -1457,26 +1501,28 @@ yyreduce:
break;
case 10:
-#line 148 "hex_grammar.y"
+#line 173 "hex_grammar.y"
{
(yyval.re_node) = (yyvsp[(1) - (1)].re_node);
}
break;
case 11:
-#line 152 "hex_grammar.y"
+#line 177 "hex_grammar.y"
{
mark_as_not_literal();
mark_as_not_fast_hex_regexp();
(yyval.re_node) = yr_re_node_create(RE_NODE_ALT, (yyvsp[(1) - (3)].re_node), (yyvsp[(3) - (3)].re_node));
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (3)].re_node));
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(3) - (3)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
}
break;
case 12:
-#line 163 "hex_grammar.y"
+#line 190 "hex_grammar.y"
{
RE* re = yyget_extra(yyscanner);
@@ -1503,7 +1549,7 @@ yyreduce:
break;
case 13:
-#line 187 "hex_grammar.y"
+#line 214 "hex_grammar.y"
{
uint8_t mask = (yyvsp[(1) - (1)].integer) >> 8;
@@ -1529,7 +1575,7 @@ yyreduce:
/* Line 1267 of yacc.c. */
-#line 1533 "hex_grammar.c"
+#line 1579 "hex_grammar.c"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -1743,7 +1789,7 @@ yyreturn:
}
-#line 210 "hex_grammar.y"
+#line 237 "hex_grammar.y"
diff --git a/libyara/hex_grammar.h b/libyara/hex_grammar.h
index 6cd377e..5d1606e 100644
--- a/libyara/hex_grammar.h
+++ b/libyara/hex_grammar.h
@@ -54,7 +54,7 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 61 "hex_grammar.y"
+#line 73 "hex_grammar.y"
{
int integer;
RE_NODE *re_node;
diff --git a/libyara/hex_grammar.y b/libyara/hex_grammar.y
index a67fde2..1bd1ca9 100644
--- a/libyara/hex_grammar.y
+++ b/libyara/hex_grammar.y
@@ -23,6 +23,12 @@ limitations under the License.
#include "re.h"
#include "yara.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
#define YYERROR_VERBOSE
#define YYDEBUG 0
@@ -45,6 +51,12 @@ yydebug = 1;
YYABORT; \
} \
+#define DESTROY_NODE_IF(x, node) \
+ if (x) \
+ { \
+ yr_re_node_destroy(node); \
+ } \
+
%}
%debug
@@ -69,6 +81,12 @@ yydebug = 1;
%type <re_node> tokens token byte alternatives range
+%destructor { yr_re_node_destroy($$); } tokens
+%destructor { yr_re_node_destroy($$); } token
+%destructor { yr_re_node_destroy($$); } byte
+%destructor { yr_re_node_destroy($$); } alternatives
+%destructor { yr_re_node_destroy($$); } range
+
%%
hex_string : '{' tokens '}'
@@ -86,6 +104,9 @@ tokens : token
| tokens token
{
$$ = yr_re_node_create(RE_NODE_CONCAT, $1, $2);
+
+ DESTROY_NODE_IF($$ == NULL, $1);
+ DESTROY_NODE_IF($$ == NULL, $2);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
}
;
@@ -113,6 +134,8 @@ range : _NUMBER_
re_any = yr_re_node_create(RE_NODE_ANY, NULL, NULL);
+ ERROR_IF(re_any == NULL, ERROR_INSUFICIENT_MEMORY);
+
$$ = yr_re_node_create(RE_NODE_RANGE, re_any, NULL);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
@@ -134,6 +157,8 @@ range : _NUMBER_
re_any = yr_re_node_create(RE_NODE_ANY, NULL, NULL);
+ ERROR_IF(re_any == NULL, ERROR_INSUFICIENT_MEMORY);
+
$$ = yr_re_node_create(RE_NODE_RANGE, re_any, NULL);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
@@ -155,6 +180,8 @@ alternatives : tokens
$$ = yr_re_node_create(RE_NODE_ALT, $1, $3);
+ DESTROY_NODE_IF($$ == NULL, $1);
+ DESTROY_NODE_IF($$ == NULL, $3);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
}
;
diff --git a/libyara/hex_lexer.c b/libyara/hex_lexer.c
index a7e4ef4..25c6c36 100644
--- a/libyara/hex_lexer.c
+++ b/libyara/hex_lexer.c
@@ -47,7 +47,6 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
-typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
@@ -358,7 +357,7 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*/
#define YY_DO_BEFORE_ACTION \
yyg->yytext_ptr = yy_bp; \
- yyleng = (yy_size_t) (yy_cp - yy_bp); \
+ yyleng = (size_t) (yy_cp - yy_bp); \
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
@@ -485,6 +484,11 @@ limitations under the License.
#include "hex_lexer.h"
#include "utils.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
#ifdef WIN32
#define snprintf _snprintf
@@ -501,7 +505,7 @@ limitations under the License.
#define YY_NO_UNISTD_H 1
#define YY_NO_INPUT 1
-#line 505 "hex_lexer.c"
+#line 509 "hex_lexer.c"
#define INITIAL 0
#define range 1
@@ -733,11 +737,11 @@ YY_DECL
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-#line 63 "hex_lexer.l"
+#line 68 "hex_lexer.l"
-#line 741 "hex_lexer.c"
+#line 745 "hex_lexer.c"
yylval = yylval_param;
@@ -836,7 +840,7 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
-#line 66 "hex_lexer.l"
+#line 71 "hex_lexer.l"
{
yylval->integer = xtoi(yytext);
@@ -845,7 +849,7 @@ YY_RULE_SETUP
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 72 "hex_lexer.l"
+#line 77 "hex_lexer.l"
{
yytext[1] = '0'; // replace ? by 0
@@ -855,7 +859,7 @@ YY_RULE_SETUP
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 79 "hex_lexer.l"
+#line 84 "hex_lexer.l"
{
yytext[0] = '0'; // replace ? by 0
@@ -865,7 +869,7 @@ YY_RULE_SETUP
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 86 "hex_lexer.l"
+#line 91 "hex_lexer.l"
{
yylval->integer = 0x0000;
@@ -874,7 +878,7 @@ YY_RULE_SETUP
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 92 "hex_lexer.l"
+#line 97 "hex_lexer.l"
{
BEGIN(range);
@@ -883,14 +887,14 @@ YY_RULE_SETUP
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 98 "hex_lexer.l"
+#line 103 "hex_lexer.l"
{
return yytext[0];
}
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 102 "hex_lexer.l"
+#line 107 "hex_lexer.l"
{
yylval->integer = atoi(yytext);
@@ -906,7 +910,7 @@ YY_RULE_SETUP
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 115 "hex_lexer.l"
+#line 120 "hex_lexer.l"
{
BEGIN(INITIAL);
@@ -916,12 +920,12 @@ YY_RULE_SETUP
case 9:
/* rule 9 can match eol */
YY_RULE_SETUP
-#line 122 "hex_lexer.l"
+#line 127 "hex_lexer.l"
// skip whitespace
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 125 "hex_lexer.l"
+#line 130 "hex_lexer.l"
{
if (yytext[0] >= 32 && yytext[0] < 127)
@@ -937,10 +941,10 @@ YY_RULE_SETUP
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 138 "hex_lexer.l"
+#line 143 "hex_lexer.l"
ECHO;
YY_BREAK
-#line 944 "hex_lexer.c"
+#line 948 "hex_lexer.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(range):
yyterminate();
@@ -2076,7 +2080,7 @@ void hex_yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables"
-#line 138 "hex_lexer.l"
+#line 143 "hex_lexer.l"
diff --git a/libyara/hex_lexer.l b/libyara/hex_lexer.l
index 96f7591..e8247b8 100644
--- a/libyara/hex_lexer.l
+++ b/libyara/hex_lexer.l
@@ -26,6 +26,11 @@ limitations under the License.
#include "hex_lexer.h"
#include "utils.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
#ifdef WIN32
#define snprintf _snprintf
diff --git a/libyara/lexer.c b/libyara/lexer.c
index 7f4aa7b..919735a 100644
--- a/libyara/lexer.c
+++ b/libyara/lexer.c
@@ -47,7 +47,6 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
-typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
@@ -358,7 +357,7 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*/
#define YY_DO_BEFORE_ACTION \
yyg->yytext_ptr = yy_bp; \
- yyleng = (yy_size_t) (yy_cp - yy_bp); \
+ yyleng = (size_t) (yy_cp - yy_bp); \
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
@@ -653,6 +652,11 @@ limitations under the License.
#include "utils.h"
#include "re.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
#define LEX_CHECK_SPACE_OK(data, current_size, max_length) \
if (strlen(data) + current_size >= max_length - 1) \
@@ -682,7 +686,7 @@ limitations under the License.
-#line 686 "lexer.c"
+#line 690 "lexer.c"
#define INITIAL 0
#define str 1
@@ -917,10 +921,10 @@ YY_DECL
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-#line 81 "lexer.l"
+#line 86 "lexer.l"
-#line 924 "lexer.c"
+#line 928 "lexer.c"
yylval = yylval_param;
@@ -1019,253 +1023,253 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
-#line 83 "lexer.l"
+#line 88 "lexer.l"
{ return _LT_; }
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 84 "lexer.l"
+#line 89 "lexer.l"
{ return _GT_; }
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 85 "lexer.l"
+#line 90 "lexer.l"
{ return _LE_; }
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 86 "lexer.l"
+#line 91 "lexer.l"
{ return _GE_; }
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 87 "lexer.l"
+#line 92 "lexer.l"
{ return _EQ_; }
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 88 "lexer.l"
+#line 93 "lexer.l"
{ return _NEQ_; }
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 89 "lexer.l"
+#line 94 "lexer.l"
{ return _SHIFT_LEFT_; }
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 90 "lexer.l"
+#line 95 "lexer.l"
{ return _SHIFT_RIGHT_; }
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 91 "lexer.l"
+#line 96 "lexer.l"
{ return _PRIVATE_; }
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 92 "lexer.l"
+#line 97 "lexer.l"
{ return _GLOBAL_; }
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 93 "lexer.l"
+#line 98 "lexer.l"
{ return _RULE_; }
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 94 "lexer.l"
+#line 99 "lexer.l"
{ return _META_; }
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 95 "lexer.l"
+#line 100 "lexer.l"
{ return _STRINGS_; }
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 96 "lexer.l"
+#line 101 "lexer.l"
{ return _ASCII_; }
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 97 "lexer.l"
+#line 102 "lexer.l"
{ return _WIDE_; }
YY_BREAK
case 16:
YY_RULE_SETUP
-#line 98 "lexer.l"
+#line 103 "lexer.l"
{ return _FULLWORD_; }
YY_BREAK
case 17:
YY_RULE_SETUP
-#line 99 "lexer.l"
+#line 104 "lexer.l"
{ return _NOCASE_; }
YY_BREAK
case 18:
YY_RULE_SETUP
-#line 100 "lexer.l"
+#line 105 "lexer.l"
{ return _CONDITION_; }
YY_BREAK
case 19:
YY_RULE_SETUP
-#line 101 "lexer.l"
+#line 106 "lexer.l"
{ return _TRUE_; }
YY_BREAK
case 20:
YY_RULE_SETUP
-#line 102 "lexer.l"
+#line 107 "lexer.l"
{ return _FALSE_; }
YY_BREAK
case 21:
YY_RULE_SETUP
-#line 103 "lexer.l"
+#line 108 "lexer.l"
{ return _NOT_; }
YY_BREAK
case 22:
YY_RULE_SETUP
-#line 104 "lexer.l"
+#line 109 "lexer.l"
{ return _AND_; }
YY_BREAK
case 23:
YY_RULE_SETUP
-#line 105 "lexer.l"
+#line 110 "lexer.l"
{ return _OR_; }
YY_BREAK
case 24:
YY_RULE_SETUP
-#line 106 "lexer.l"
+#line 111 "lexer.l"
{ return _AT_; }
YY_BREAK
case 25:
YY_RULE_SETUP
-#line 107 "lexer.l"
+#line 112 "lexer.l"
{ return _IN_; }
YY_BREAK
case 26:
YY_RULE_SETUP
-#line 108 "lexer.l"
+#line 113 "lexer.l"
{ return _OF_; }
YY_BREAK
case 27:
YY_RULE_SETUP
-#line 109 "lexer.l"
+#line 114 "lexer.l"
{ return _THEM_; }
YY_BREAK
case 28:
YY_RULE_SETUP
-#line 110 "lexer.l"
+#line 115 "lexer.l"
{ return _FOR_; }
YY_BREAK
case 29:
YY_RULE_SETUP
-#line 111 "lexer.l"
+#line 116 "lexer.l"
{ return _ALL_; }
YY_BREAK
case 30:
YY_RULE_SETUP
-#line 112 "lexer.l"
+#line 117 "lexer.l"
{ return _ANY_; }
YY_BREAK
case 31:
YY_RULE_SETUP
-#line 113 "lexer.l"
+#line 118 "lexer.l"
{ return _ENTRYPOINT_; }
YY_BREAK
case 32:
YY_RULE_SETUP
-#line 114 "lexer.l"
+#line 119 "lexer.l"
{ return _SIZE_; }
YY_BREAK
case 33:
YY_RULE_SETUP
-#line 115 "lexer.l"
+#line 120 "lexer.l"
{ return _RVA_; }
YY_BREAK
case 34:
YY_RULE_SETUP
-#line 116 "lexer.l"
+#line 121 "lexer.l"
{ return _OFFSET_; }
YY_BREAK
case 35:
YY_RULE_SETUP
-#line 117 "lexer.l"
+#line 122 "lexer.l"
{ return _FILE_; }
YY_BREAK
case 36:
YY_RULE_SETUP
-#line 118 "lexer.l"
+#line 123 "lexer.l"
{ return _SECTION_; }
YY_BREAK
case 37:
YY_RULE_SETUP
-#line 119 "lexer.l"
+#line 124 "lexer.l"
{ return _UINT8_; }
YY_BREAK
case 38:
YY_RULE_SETUP
-#line 120 "lexer.l"
+#line 125 "lexer.l"
{ return _UINT16_; }
YY_BREAK
case 39:
YY_RULE_SETUP
-#line 121 "lexer.l"
+#line 126 "lexer.l"
{ return _UINT32_; }
YY_BREAK
case 40:
YY_RULE_SETUP
-#line 122 "lexer.l"
+#line 127 "lexer.l"
{ return _INT8_; }
YY_BREAK
case 41:
YY_RULE_SETUP
-#line 123 "lexer.l"
+#line 128 "lexer.l"
{ return _INT16_; }
YY_BREAK
case 42:
YY_RULE_SETUP
-#line 124 "lexer.l"
+#line 129 "lexer.l"
{ return _INT32_; }
YY_BREAK
case 43:
YY_RULE_SETUP
-#line 125 "lexer.l"
+#line 130 "lexer.l"
{ return _MATCHES_; }
YY_BREAK
case 44:
YY_RULE_SETUP
-#line 126 "lexer.l"
+#line 131 "lexer.l"
{ return _CONTAINS_; }
YY_BREAK
case 45:
YY_RULE_SETUP
-#line 127 "lexer.l"
+#line 132 "lexer.l"
{ return _INDEX_; }
YY_BREAK
case 46:
YY_RULE_SETUP
-#line 130 "lexer.l"
+#line 135 "lexer.l"
{ BEGIN(comment); }
YY_BREAK
case 47:
YY_RULE_SETUP
-#line 131 "lexer.l"
+#line 136 "lexer.l"
{ BEGIN(INITIAL); }
YY_BREAK
case 48:
/* rule 48 can match eol */
YY_RULE_SETUP
-#line 132 "lexer.l"
+#line 137 "lexer.l"
{ /* skip comments */ }
YY_BREAK
case 49:
YY_RULE_SETUP
-#line 135 "lexer.l"
+#line 140 "lexer.l"
{ /* skip single-line comments */ }
YY_BREAK
case 50:
YY_RULE_SETUP
-#line 138 "lexer.l"
+#line 143 "lexer.l"
{
yyextra->lex_buf_ptr = yyextra->lex_buf;
yyextra->lex_buf_len = 0;
@@ -1275,12 +1279,12 @@ YY_RULE_SETUP
case 51:
/* rule 51 can match eol */
YY_RULE_SETUP
-#line 145 "lexer.l"
+#line 150 "lexer.l"
{ YYTEXT_TO_BUFFER; }
YY_BREAK
case 52:
YY_RULE_SETUP
-#line 148 "lexer.l"
+#line 153 "lexer.l"
{
char buffer[1024];
@@ -1382,7 +1386,7 @@ case YY_STATE_EOF(str):
case YY_STATE_EOF(regexp):
case YY_STATE_EOF(include):
case YY_STATE_EOF(comment):
-#line 246 "lexer.l"
+#line 251 "lexer.l"
{
YR_COMPILER* compiler = yara_yyget_extra(yyscanner);
@@ -1404,7 +1408,7 @@ case YY_STATE_EOF(comment):
YY_BREAK
case 53:
YY_RULE_SETUP
-#line 266 "lexer.l"
+#line 271 "lexer.l"
{
yylval->c_string = yr_strdup(yytext);
@@ -1413,7 +1417,7 @@ YY_RULE_SETUP
YY_BREAK
case 54:
YY_RULE_SETUP
-#line 273 "lexer.l"
+#line 278 "lexer.l"
{
yylval->c_string = yr_strdup(yytext);
@@ -1422,7 +1426,7 @@ YY_RULE_SETUP
YY_BREAK
case 55:
YY_RULE_SETUP
-#line 280 "lexer.l"
+#line 285 "lexer.l"
{
yylval->c_string = yr_strdup(yytext);
@@ -1432,7 +1436,7 @@ YY_RULE_SETUP
YY_BREAK
case 56:
YY_RULE_SETUP
-#line 288 "lexer.l"
+#line 293 "lexer.l"
{
yylval->c_string = yr_strdup(yytext);
@@ -1442,7 +1446,7 @@ YY_RULE_SETUP
YY_BREAK
case 57:
YY_RULE_SETUP
-#line 296 "lexer.l"
+#line 301 "lexer.l"
{
if (strlen(yytext) > 128)
@@ -1456,7 +1460,7 @@ YY_RULE_SETUP
YY_BREAK
case 58:
YY_RULE_SETUP
-#line 308 "lexer.l"
+#line 313 "lexer.l"
{
yylval->integer = (size_t) atol(yytext);
@@ -1474,7 +1478,7 @@ YY_RULE_SETUP
YY_BREAK
case 59:
YY_RULE_SETUP
-#line 324 "lexer.l"
+#line 329 "lexer.l"
{
yylval->integer = xtoi(yytext + 2);
@@ -1483,7 +1487,7 @@ YY_RULE_SETUP
YY_BREAK
case 60:
YY_RULE_SETUP
-#line 331 "lexer.l"
+#line 336 "lexer.l"
{ /* saw closing quote - all done */
SIZED_STRING* s;
@@ -1507,7 +1511,7 @@ YY_RULE_SETUP
YY_BREAK
case 61:
YY_RULE_SETUP
-#line 353 "lexer.l"
+#line 358 "lexer.l"
{
LEX_CHECK_SPACE_OK("\t", yyextra->lex_buf_len, LEX_BUF_SIZE);
@@ -1517,7 +1521,7 @@ YY_RULE_SETUP
YY_BREAK
case 62:
YY_RULE_SETUP
-#line 361 "lexer.l"
+#line 366 "lexer.l"
{
LEX_CHECK_SPACE_OK("\"", yyextra->lex_buf_len, LEX_BUF_SIZE);
@@ -1527,7 +1531,7 @@ YY_RULE_SETUP
YY_BREAK
case 63:
YY_RULE_SETUP
-#line 369 "lexer.l"
+#line 374 "lexer.l"
{
LEX_CHECK_SPACE_OK("\\", yyextra->lex_buf_len, LEX_BUF_SIZE);
@@ -1537,7 +1541,7 @@ YY_RULE_SETUP
YY_BREAK
case 64:
YY_RULE_SETUP
-#line 377 "lexer.l"
+#line 382 "lexer.l"
{
int result;
@@ -1550,13 +1554,13 @@ YY_RULE_SETUP
YY_BREAK
case 65:
YY_RULE_SETUP
-#line 388 "lexer.l"
+#line 393 "lexer.l"
{ YYTEXT_TO_BUFFER; }
YY_BREAK
case 66:
/* rule 66 can match eol */
YY_RULE_SETUP
-#line 391 "lexer.l"
+#line 396 "lexer.l"
{
yyerror(yyscanner, "unterminated string");
@@ -1566,7 +1570,7 @@ YY_RULE_SETUP
case 67:
/* rule 67 can match eol */
YY_RULE_SETUP
-#line 397 "lexer.l"
+#line 402 "lexer.l"
{
yyerror(yyscanner, "illegal escape sequence");
@@ -1574,7 +1578,7 @@ YY_RULE_SETUP
YY_BREAK
case 68:
YY_RULE_SETUP
-#line 403 "lexer.l"
+#line 408 "lexer.l"
{
SIZED_STRING* s;
@@ -1605,7 +1609,7 @@ YY_RULE_SETUP
YY_BREAK
case 69:
YY_RULE_SETUP
-#line 432 "lexer.l"
+#line 437 "lexer.l"
{
LEX_CHECK_SPACE_OK("/", yyextra->lex_buf_len, LEX_BUF_SIZE);
@@ -1615,7 +1619,7 @@ YY_RULE_SETUP
YY_BREAK
case 70:
YY_RULE_SETUP
-#line 440 "lexer.l"
+#line 445 "lexer.l"
{
LEX_CHECK_SPACE_OK("\\.", yyextra->lex_buf_len, LEX_BUF_SIZE);
@@ -1626,13 +1630,13 @@ YY_RULE_SETUP
YY_BREAK
case 71:
YY_RULE_SETUP
-#line 449 "lexer.l"
+#line 454 "lexer.l"
{ YYTEXT_TO_BUFFER; }
YY_BREAK
case 72:
/* rule 72 can match eol */
YY_RULE_SETUP
-#line 452 "lexer.l"
+#line 457 "lexer.l"
{
yyerror(yyscanner, "unterminated regular expression");
@@ -1641,7 +1645,7 @@ YY_RULE_SETUP
YY_BREAK
case 73:
YY_RULE_SETUP
-#line 459 "lexer.l"
+#line 464 "lexer.l"
{
yyextra->lex_buf_ptr = yyextra->lex_buf;
@@ -1651,7 +1655,7 @@ YY_RULE_SETUP
YY_BREAK
case 74:
YY_RULE_SETUP
-#line 467 "lexer.l"
+#line 472 "lexer.l"
{
yyextra->lex_buf_ptr = yyextra->lex_buf;
@@ -1662,7 +1666,7 @@ YY_RULE_SETUP
case 75:
/* rule 75 can match eol */
YY_RULE_SETUP
-#line 475 "lexer.l"
+#line 480 "lexer.l"
{
int len = strlen(yytext);
@@ -1678,12 +1682,12 @@ YY_RULE_SETUP
case 76:
/* rule 76 can match eol */
YY_RULE_SETUP
-#line 488 "lexer.l"
+#line 493 "lexer.l"
/* skip whitespace */
YY_BREAK
case 77:
YY_RULE_SETUP
-#line 490 "lexer.l"
+#line 495 "lexer.l"
{
if (yytext[0] >= 32 && yytext[0] < 127)
@@ -1699,10 +1703,10 @@ YY_RULE_SETUP
YY_BREAK
case 78:
YY_RULE_SETUP
-#line 503 "lexer.l"
+#line 508 "lexer.l"
ECHO;
YY_BREAK
-#line 1706 "lexer.c"
+#line 1710 "lexer.c"
case YY_END_OF_BUFFER:
{
@@ -2835,7 +2839,7 @@ void yara_yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables"
-#line 503 "lexer.l"
+#line 508 "lexer.l"
diff --git a/libyara/lexer.l b/libyara/lexer.l
index eeea6d7..15ef042 100644
--- a/libyara/lexer.l
+++ b/libyara/lexer.l
@@ -32,6 +32,11 @@ limitations under the License.
#include "utils.h"
#include "re.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
#define LEX_CHECK_SPACE_OK(data, current_size, max_length) \
if (strlen(data) + current_size >= max_length - 1) \
diff --git a/libyara/mem.h b/libyara/mem.h
index f4cf2e0..a80f53f 100644
--- a/libyara/mem.h
+++ b/libyara/mem.h
@@ -19,9 +19,18 @@ limitations under the License.
#include <stdio.h>
-void yr_heap_alloc();
+#include "config.h"
-void yr_heap_free();
+#ifdef DMALLOC
+
+#define yr_malloc malloc
+#define yr_realloc realloc
+#define yr_free free
+#define yr_strdup strdup
+
+#include <dmalloc.h>
+
+#else
void* yr_malloc(
size_t size);
@@ -38,4 +47,10 @@ char* yr_strdup(
#endif
+void yr_heap_alloc();
+
+void yr_heap_free();
+
+#endif
+
diff --git a/libyara/re.h b/libyara/re.h
index bbeb5a3..3e12cd2 100644
--- a/libyara/re.h
+++ b/libyara/re.h
@@ -156,6 +156,16 @@ void yr_re_print(
RE* re);
+RE_NODE* yr_re_node_create(
+ int type,
+ RE_NODE* left,
+ RE_NODE* right);
+
+
+void yr_re_node_destroy(
+ RE_NODE* node);
+
+
int yr_re_emit_code(
RE* re,
YR_ARENA* arena);
diff --git a/libyara/re_grammar.c b/libyara/re_grammar.c
index d0dda82..244f18c 100644
--- a/libyara/re_grammar.c
+++ b/libyara/re_grammar.c
@@ -111,6 +111,12 @@
#include "re_lexer.h"
#include "re.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
#define YYERROR_VERBOSE
@@ -133,6 +139,12 @@ yydebug = 1;
YYABORT; \
} \
+#define DESTROY_NODE_IF(x, node) \
+ if (x) \
+ { \
+ yr_re_node_destroy(node); \
+ } \
+
/* Enabling traces. */
@@ -155,7 +167,7 @@ yydebug = 1;
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 60 "re_grammar.y"
+#line 72 "re_grammar.y"
{
int integer;
uint32_t range;
@@ -163,7 +175,7 @@ typedef union YYSTYPE
uint8_t* class_vector;
}
/* Line 193 of yacc.c. */
-#line 167 "re_grammar.c"
+#line 179 "re_grammar.c"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
@@ -176,7 +188,7 @@ typedef union YYSTYPE
/* Line 216 of yacc.c. */
-#line 180 "re_grammar.c"
+#line 192 "re_grammar.c"
#ifdef short
# undef short
@@ -467,9 +479,9 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 86, 86, 91, 94, 98, 105, 120, 124, 132,
- 139, 148, 155, 164, 174, 185, 195, 199, 206, 215,
- 219, 226, 249, 256, 263, 270, 277, 284, 291
+ 0, 101, 101, 106, 109, 113, 123, 139, 143, 153,
+ 161, 171, 179, 189, 200, 212, 223, 227, 234, 243,
+ 247, 254, 277, 284, 291, 298, 305, 312, 319
};
#endif
@@ -1098,9 +1110,29 @@ yydestruct (yymsg, yytype, yyvaluep, yyscanner, lex_env)
switch (yytype)
{
case 6: /* "_CLASS_" */
-#line 79 "re_grammar.y"
+#line 93 "re_grammar.y"
{ yr_free((yyvaluep->class_vector)); };
-#line 1104 "re_grammar.c"
+#line 1116 "re_grammar.c"
+ break;
+ case 24: /* "alternative" */
+#line 94 "re_grammar.y"
+ { yr_re_node_destroy((yyvaluep->re_node)); };
+#line 1121 "re_grammar.c"
+ break;
+ case 25: /* "concatenation" */
+#line 95 "re_grammar.y"
+ { yr_re_node_destroy((yyvaluep->re_node)); };
+#line 1126 "re_grammar.c"
+ break;
+ case 26: /* "repeat" */
+#line 96 "re_grammar.y"
+ { yr_re_node_destroy((yyvaluep->re_node)); };
+#line 1131 "re_grammar.c"
+ break;
+ case 27: /* "single" */
+#line 97 "re_grammar.y"
+ { yr_re_node_destroy((yyvaluep->re_node)); };
+#line 1136 "re_grammar.c"
break;
default:
@@ -1410,7 +1442,7 @@ yyreduce:
switch (yyn)
{
case 2:
-#line 87 "re_grammar.y"
+#line 102 "re_grammar.y"
{
RE* re = yyget_extra(yyscanner);
re->root_node = (yyvsp[(1) - (1)].re_node);
@@ -1418,30 +1450,34 @@ yyreduce:
break;
case 4:
-#line 95 "re_grammar.y"
+#line 110 "re_grammar.y"
{
(yyval.re_node) = (yyvsp[(1) - (1)].re_node);
}
break;
case 5:
-#line 99 "re_grammar.y"
+#line 114 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_ALT, (yyvsp[(1) - (3)].re_node), (yyvsp[(3) - (3)].re_node));
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (3)].re_node));
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(3) - (3)].re_node));
+
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
}
break;
case 6:
-#line 106 "re_grammar.y"
+#line 124 "re_grammar.y"
{
RE_NODE* node;
mark_as_not_literal();
node = yr_re_node_create(RE_NODE_EMPTY, NULL, NULL);
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (2)].re_node));
ERROR_IF(node == NULL, ERROR_INSUFICIENT_MEMORY);
(yyval.re_node) = yr_re_node_create(RE_NODE_ALT, (yyvsp[(1) - (2)].re_node), node);
@@ -1451,37 +1487,41 @@ yyreduce:
break;
case 7:
-#line 121 "re_grammar.y"
+#line 140 "re_grammar.y"
{
(yyval.re_node) = (yyvsp[(1) - (1)].re_node);
}
break;
case 8:
-#line 125 "re_grammar.y"
+#line 144 "re_grammar.y"
{
(yyval.re_node) = yr_re_node_create(RE_NODE_CONCAT, (yyvsp[(1) - (2)].re_node), (yyvsp[(2) - (2)].re_node));
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (2)].re_node));
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(2) - (2)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
}
break;
case 9:
-#line 133 "re_grammar.y"
+#line 154 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_STAR, (yyvsp[(1) - (2)].re_node), NULL);
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (2)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
}
break;
case 10:
-#line 140 "re_grammar.y"
+#line 162 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_STAR, (yyvsp[(1) - (3)].re_node), NULL);
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (3)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
(yyval.re_node)->greedy = FALSE;
@@ -1489,21 +1529,23 @@ yyreduce:
break;
case 11:
-#line 149 "re_grammar.y"
+#line 172 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_PLUS, (yyvsp[(1) - (2)].re_node), NULL);
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (2)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
}
break;
case 12:
-#line 156 "re_grammar.y"
+#line 180 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_PLUS, (yyvsp[(1) - (3)].re_node), NULL);
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (3)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
(yyval.re_node)->greedy = FALSE;
@@ -1511,11 +1553,12 @@ yyreduce:
break;
case 13:
-#line 165 "re_grammar.y"
+#line 190 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_RANGE, (yyvsp[(1) - (2)].re_node), NULL);
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (2)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
(yyval.re_node)->start = 0;
@@ -1524,11 +1567,12 @@ yyreduce:
break;
case 14:
-#line 175 "re_grammar.y"
+#line 201 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_RANGE, (yyvsp[(1) - (3)].re_node), NULL);
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (3)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
(yyval.re_node)->start = 0;
@@ -1538,11 +1582,12 @@ yyreduce:
break;
case 15:
-#line 186 "re_grammar.y"
+#line 213 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_RANGE, (yyvsp[(1) - (2)].re_node), NULL);
+ DESTROY_NODE_IF((yyval.re_node) == NULL, (yyvsp[(1) - (2)].re_node));
ERROR_IF((yyval.re_node) == NULL, ERROR_INSUFICIENT_MEMORY);
(yyval.re_node)->start = (yyvsp[(2) - (2)].range) & 0xFFFF;;
@@ -1551,14 +1596,14 @@ yyreduce:
break;
case 16:
-#line 196 "re_grammar.y"
+#line 224 "re_grammar.y"
{
(yyval.re_node) = (yyvsp[(1) - (1)].re_node);
}
break;
case 17:
-#line 200 "re_grammar.y"
+#line 228 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_ANCHOR_START, NULL, NULL);
@@ -1568,7 +1613,7 @@ yyreduce:
break;
case 18:
-#line 207 "re_grammar.y"
+#line 235 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_ANCHOR_END, NULL, NULL);
@@ -1578,14 +1623,14 @@ yyreduce:
break;
case 19:
-#line 216 "re_grammar.y"
+#line 244 "re_grammar.y"
{
(yyval.re_node) = (yyvsp[(2) - (3)].re_node);
}
break;
case 20:
-#line 220 "re_grammar.y"
+#line 248 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_ANY, NULL, NULL);
@@ -1595,7 +1640,7 @@ yyreduce:
break;
case 21:
-#line 227 "re_grammar.y"
+#line 255 "re_grammar.y"
{
RE* re = yyget_extra(yyscanner);
@@ -1621,7 +1666,7 @@ yyreduce:
break;
case 22:
-#line 250 "re_grammar.y"
+#line 278 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_WORD_CHAR, NULL, NULL);
@@ -1631,7 +1676,7 @@ yyreduce:
break;
case 23:
-#line 257 "re_grammar.y"
+#line 285 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_NON_WORD_CHAR, NULL, NULL);
@@ -1641,7 +1686,7 @@ yyreduce:
break;
case 24:
-#line 264 "re_grammar.y"
+#line 292 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_SPACE, NULL, NULL);
@@ -1651,7 +1696,7 @@ yyreduce:
break;
case 25:
-#line 271 "re_grammar.y"
+#line 299 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_NON_SPACE, NULL, NULL);
@@ -1661,7 +1706,7 @@ yyreduce:
break;
case 26:
-#line 278 "re_grammar.y"
+#line 306 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_DIGIT, NULL, NULL);
@@ -1671,7 +1716,7 @@ yyreduce:
break;
case 27:
-#line 285 "re_grammar.y"
+#line 313 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_NON_DIGIT, NULL, NULL);
@@ -1681,7 +1726,7 @@ yyreduce:
break;
case 28:
-#line 292 "re_grammar.y"
+#line 320 "re_grammar.y"
{
mark_as_not_literal();
(yyval.re_node) = yr_re_node_create(RE_NODE_CLASS, NULL, NULL);
@@ -1694,7 +1739,7 @@ yyreduce:
/* Line 1267 of yacc.c. */
-#line 1698 "re_grammar.c"
+#line 1743 "re_grammar.c"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -1908,7 +1953,7 @@ yyreturn:
}
-#line 303 "re_grammar.y"
+#line 331 "re_grammar.y"
diff --git a/libyara/re_grammar.h b/libyara/re_grammar.h
index ec0ec17..d4095f6 100644
--- a/libyara/re_grammar.h
+++ b/libyara/re_grammar.h
@@ -68,7 +68,7 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 60 "re_grammar.y"
+#line 72 "re_grammar.y"
{
int integer;
uint32_t range;
diff --git a/libyara/re_grammar.y b/libyara/re_grammar.y
index 0e9ca88..268677e 100644
--- a/libyara/re_grammar.y
+++ b/libyara/re_grammar.y
@@ -22,6 +22,12 @@ limitations under the License.
#include "re_lexer.h"
#include "re.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
#define YYERROR_VERBOSE
@@ -44,6 +50,12 @@ yydebug = 1;
YYABORT; \
} \
+#define DESTROY_NODE_IF(x, node) \
+ if (x) \
+ { \
+ yr_re_node_destroy(node); \
+ } \
+
%}
%debug
@@ -76,11 +88,14 @@ yydebug = 1;
%token _DIGIT_
%token _NON_DIGIT_
-%destructor { yr_free($$); } _CLASS_
-
-
%type <re_node> alternative concatenation repeat single
+%destructor { yr_free($$); } _CLASS_
+%destructor { yr_re_node_destroy($$); } alternative
+%destructor { yr_re_node_destroy($$); } concatenation
+%destructor { yr_re_node_destroy($$); } repeat
+%destructor { yr_re_node_destroy($$); } single
+
%%
re : alternative
@@ -100,6 +115,9 @@ alternative : concatenation
mark_as_not_literal();
$$ = yr_re_node_create(RE_NODE_ALT, $1, $3);
+ DESTROY_NODE_IF($$ == NULL, $1);
+ DESTROY_NODE_IF($$ == NULL, $3);
+
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
}
| alternative '|'
@@ -109,6 +127,7 @@ alternative : concatenation
mark_as_not_literal();
node = yr_re_node_create(RE_NODE_EMPTY, NULL, NULL);
+ DESTROY_NODE_IF($$ == NULL, $1);
ERROR_IF(node == NULL, ERROR_INSUFICIENT_MEMORY);
$$ = yr_re_node_create(RE_NODE_ALT, $1, node);
@@ -125,6 +144,8 @@ concatenation : repeat
{
$$ = yr_re_node_create(RE_NODE_CONCAT, $1, $2);
+ DESTROY_NODE_IF($$ == NULL, $1);
+ DESTROY_NODE_IF($$ == NULL, $2);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
}
;
@@ -134,6 +155,7 @@ repeat : single '*'
mark_as_not_literal();
$$ = yr_re_node_create(RE_NODE_STAR, $1, NULL);
+ DESTROY_NODE_IF($$ == NULL, $1);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
}
| single '*' '?'
@@ -141,6 +163,7 @@ repeat : single '*'
mark_as_not_literal();
$$ = yr_re_node_create(RE_NODE_STAR, $1, NULL);
+ DESTROY_NODE_IF($$ == NULL, $1);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
$$->greedy = FALSE;
@@ -150,6 +173,7 @@ repeat : single '*'
mark_as_not_literal();
$$ = yr_re_node_create(RE_NODE_PLUS, $1, NULL);
+ DESTROY_NODE_IF($$ == NULL, $1);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
}
| single '+' '?'
@@ -157,6 +181,7 @@ repeat : single '*'
mark_as_not_literal();
$$ = yr_re_node_create(RE_NODE_PLUS, $1, NULL);
+ DESTROY_NODE_IF($$ == NULL, $1);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
$$->greedy = FALSE;
@@ -166,6 +191,7 @@ repeat : single '*'
mark_as_not_literal();
$$ = yr_re_node_create(RE_NODE_RANGE, $1, NULL);
+ DESTROY_NODE_IF($$ == NULL, $1);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
$$->start = 0;
@@ -176,6 +202,7 @@ repeat : single '*'
mark_as_not_literal();
$$ = yr_re_node_create(RE_NODE_RANGE, $1, NULL);
+ DESTROY_NODE_IF($$ == NULL, $1);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
$$->start = 0;
@@ -187,6 +214,7 @@ repeat : single '*'
mark_as_not_literal();
$$ = yr_re_node_create(RE_NODE_RANGE, $1, NULL);
+ DESTROY_NODE_IF($$ == NULL, $1);
ERROR_IF($$ == NULL, ERROR_INSUFICIENT_MEMORY);
$$->start = $2 & 0xFFFF;;
diff --git a/libyara/re_lexer.c b/libyara/re_lexer.c
index d5ffa6b..6d6e1c4 100644
--- a/libyara/re_lexer.c
+++ b/libyara/re_lexer.c
@@ -47,7 +47,6 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
-typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
@@ -358,7 +357,7 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*/
#define YY_DO_BEFORE_ACTION \
yyg->yytext_ptr = yy_bp; \
- yyleng = (yy_size_t) (yy_cp - yy_bp); \
+ yyleng = (size_t) (yy_cp - yy_bp); \
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
@@ -506,6 +505,12 @@ limitations under the License.
#include "re_lexer.h"
#include "utils.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
#ifdef WIN32
#define snprintf _snprintf
@@ -516,7 +521,7 @@ uint8_t read_escaped_char(yyscan_t yyscanner);
#define YY_NO_UNISTD_H 1
-#line 520 "re_lexer.c"
+#line 525 "re_lexer.c"
#define INITIAL 0
#define char_class 1
@@ -750,10 +755,10 @@ YY_DECL
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-#line 55 "re_lexer.l"
+#line 61 "re_lexer.l"
-#line 757 "re_lexer.c"
+#line 762 "re_lexer.c"
yylval = yylval_param;
@@ -852,7 +857,7 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
-#line 57 "re_lexer.l"
+#line 63 "re_lexer.l"
{
// Examples: {3,8} {0,5} {,5} {7,}
@@ -888,7 +893,7 @@ YY_RULE_SETUP
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 91 "re_lexer.l"
+#line 97 "re_lexer.l"
{
// Example: {10}
@@ -908,7 +913,7 @@ YY_RULE_SETUP
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 109 "re_lexer.l"
+#line 115 "re_lexer.l"
{
// Start of a negated character class. Example: [^abcd]
@@ -920,7 +925,7 @@ YY_RULE_SETUP
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 118 "re_lexer.l"
+#line 124 "re_lexer.l"
{
// Start of character negated class containing a ].
@@ -935,7 +940,7 @@ YY_RULE_SETUP
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 131 "re_lexer.l"
+#line 137 "re_lexer.l"
{
// Start of character class containing a ].
@@ -950,7 +955,7 @@ YY_RULE_SETUP
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 144 "re_lexer.l"
+#line 150 "re_lexer.l"
{
// Start of character class. Example: [abcd]
@@ -963,7 +968,7 @@ YY_RULE_SETUP
case 7:
/* rule 7 can match eol */
YY_RULE_SETUP
-#line 154 "re_lexer.l"
+#line 160 "re_lexer.l"
{
// Any non-special character is passed as a CHAR token to the scanner.
@@ -974,49 +979,49 @@ YY_RULE_SETUP
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 163 "re_lexer.l"
+#line 169 "re_lexer.l"
{
return _WORD_CHAR_;
}
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 168 "re_lexer.l"
+#line 174 "re_lexer.l"
{
return _NON_WORD_CHAR_;
}
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 173 "re_lexer.l"
+#line 179 "re_lexer.l"
{
return _SPACE_;
}
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 178 "re_lexer.l"
+#line 184 "re_lexer.l"
{
return _NON_SPACE_;
}
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 183 "re_lexer.l"
+#line 189 "re_lexer.l"
{
return _DIGIT_;
}
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 188 "re_lexer.l"
+#line 194 "re_lexer.l"
{
return _NON_DIGIT_;
}
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 193 "re_lexer.l"
+#line 199 "re_lexer.l"
{
yyerror(yyscanner, lex_env, "backreferences are not allowed");
@@ -1025,7 +1030,7 @@ YY_RULE_SETUP
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 200 "re_lexer.l"
+#line 206 "re_lexer.l"
{
yylval->integer = read_escaped_char(yyscanner);
return _CHAR_;
@@ -1033,7 +1038,7 @@ YY_RULE_SETUP
YY_BREAK
case 16:
YY_RULE_SETUP
-#line 206 "re_lexer.l"
+#line 212 "re_lexer.l"
{
// End of character class.
@@ -1056,7 +1061,7 @@ YY_RULE_SETUP
case 17:
/* rule 17 can match eol */
YY_RULE_SETUP
-#line 226 "re_lexer.l"
+#line 232 "re_lexer.l"
{
// A range inside a character class.
@@ -1085,7 +1090,7 @@ YY_RULE_SETUP
YY_BREAK
case 18:
YY_RULE_SETUP
-#line 253 "re_lexer.l"
+#line 259 "re_lexer.l"
{
LEX_ENV->class_vector[']' / 8] |= 1 << ']' % 8;
@@ -1093,7 +1098,7 @@ YY_RULE_SETUP
YY_BREAK
case 19:
YY_RULE_SETUP
-#line 259 "re_lexer.l"
+#line 265 "re_lexer.l"
{
int i;
@@ -1108,7 +1113,7 @@ YY_RULE_SETUP
YY_BREAK
case 20:
YY_RULE_SETUP
-#line 272 "re_lexer.l"
+#line 278 "re_lexer.l"
{
int i;
@@ -1123,7 +1128,7 @@ YY_RULE_SETUP
YY_BREAK
case 21:
YY_RULE_SETUP
-#line 285 "re_lexer.l"
+#line 291 "re_lexer.l"
{
LEX_ENV->class_vector[' ' / 8] |= 1 << ' ' % 8;
@@ -1132,7 +1137,7 @@ YY_RULE_SETUP
YY_BREAK
case 22:
YY_RULE_SETUP
-#line 292 "re_lexer.l"
+#line 298 "re_lexer.l"
{
int i;
@@ -1146,7 +1151,7 @@ YY_RULE_SETUP
YY_BREAK
case 23:
YY_RULE_SETUP
-#line 304 "re_lexer.l"
+#line 310 "re_lexer.l"
{
char c;
@@ -1157,7 +1162,7 @@ YY_RULE_SETUP
YY_BREAK
case 24:
YY_RULE_SETUP
-#line 313 "re_lexer.l"
+#line 319 "re_lexer.l"
{
int i;
@@ -1172,7 +1177,7 @@ YY_RULE_SETUP
YY_BREAK
case 25:
YY_RULE_SETUP
-#line 326 "re_lexer.l"
+#line 332 "re_lexer.l"
{
uint8_t c = read_escaped_char(yyscanner);
@@ -1182,7 +1187,7 @@ YY_RULE_SETUP
case 26:
/* rule 26 can match eol */
YY_RULE_SETUP
-#line 333 "re_lexer.l"
+#line 339 "re_lexer.l"
{
// A character class (i.e: [0-9a-f]) is represented by a 256-bits vector,
@@ -1192,7 +1197,7 @@ YY_RULE_SETUP
}
YY_BREAK
case YY_STATE_EOF(char_class):
-#line 342 "re_lexer.l"
+#line 348 "re_lexer.l"
{
// End of regexp reached while scanning a character class.
@@ -1203,7 +1208,7 @@ case YY_STATE_EOF(char_class):
YY_BREAK
case 27:
YY_RULE_SETUP
-#line 351 "re_lexer.l"
+#line 357 "re_lexer.l"
{
if (yytext[0] >= 32 && yytext[0] < 127)
@@ -1218,7 +1223,7 @@ YY_RULE_SETUP
}
YY_BREAK
case YY_STATE_EOF(INITIAL):
-#line 365 "re_lexer.l"
+#line 371 "re_lexer.l"
{
yyterminate();
@@ -1226,10 +1231,10 @@ case YY_STATE_EOF(INITIAL):
YY_BREAK
case 28:
YY_RULE_SETUP
-#line 370 "re_lexer.l"
+#line 376 "re_lexer.l"
ECHO;
YY_BREAK
-#line 1233 "re_lexer.c"
+#line 1238 "re_lexer.c"
case YY_END_OF_BUFFER:
{
@@ -2404,7 +2409,7 @@ void re_yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables"
-#line 370 "re_lexer.l"
+#line 376 "re_lexer.l"
diff --git a/libyara/re_lexer.l b/libyara/re_lexer.l
index eae13a4..a504377 100644
--- a/libyara/re_lexer.l
+++ b/libyara/re_lexer.l
@@ -26,6 +26,12 @@ limitations under the License.
#include "re_lexer.h"
#include "utils.h"
+#include "config.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
#ifdef WIN32
#define snprintf _snprintf
diff --git a/yara.c b/yara.c
index 1b678a1..1853188 100644
--- a/yara.c
+++ b/yara.c
@@ -40,6 +40,10 @@ limitations under the License.
#include "threading.h"
#include "config.h"
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
#define USAGE \
"usage: yara [OPTION]... RULES_FILE FILE | PID\n"\
"options:\n"\
@@ -860,6 +864,7 @@ int main(
if (argc == 1 || optind == argc)
{
show_help();
+ cleanup();
return 0;
}
@@ -871,6 +876,8 @@ int main(
result == ERROR_CORRUPT_FILE)
{
print_scanning_error(result);
+ yr_finalize();
+ cleanup();
return 0;
}
@@ -909,7 +916,11 @@ int main(
else
{
if (yr_compiler_create(&compiler) != ERROR_SUCCESS)
+ {
+ yr_finalize();
+ cleanup();
return 0;
+ }
external = externals_list;
@@ -960,12 +971,15 @@ int main(
if (errors > 0)
{
yr_finalize();
+ cleanup();
return 0;
}
}
else
{
fprintf(stderr, "could not open file: %s\n", argv[optind]);
+ yr_finalize();
+ cleanup();
return 0;
}
}
diff --git a/yarac.c b/yarac.c
index d52a582..d41f980 100644
--- a/yarac.c
+++ b/yarac.c
@@ -176,18 +176,23 @@ int main(
yr_initialize();
if (yr_compiler_create(&compiler) != ERROR_SUCCESS)
+ {
+ yr_finalize();
return 0;
+ }
if (!process_cmd_line(compiler, argc, argv))
{
yr_compiler_destroy(compiler);
+ yr_finalize();
return 0;
}
if (argc == 1 || optind == argc)
{
- yr_compiler_destroy(compiler);
show_help();
+ yr_compiler_destroy(compiler);
+ yr_finalize();
return 0;
}
@@ -210,6 +215,7 @@ int main(
if (errors) // errors during compilation
{
yr_compiler_destroy(compiler);
+ yr_finalize();
return 0;
}
}
@@ -230,6 +236,8 @@ int main(
yr_rules_destroy(rules);
yr_compiler_destroy(compiler);
+ yr_finalize();
+
return 1;
}
--
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