Coverage Report

Created: 2026-08-28 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/yara/libyara/re_lexer.c
Line
Count
Source
1
#line 1 "libyara/re_lexer.c"
2
3
#line 3 "libyara/re_lexer.c"
4
5
#define  YY_INT_ALIGNED short int
6
7
/* A lexical scanner generated by flex */
8
9
#define FLEX_SCANNER
10
#define YY_FLEX_MAJOR_VERSION 2
11
#define YY_FLEX_MINOR_VERSION 6
12
#define YY_FLEX_SUBMINOR_VERSION 4
13
#if YY_FLEX_SUBMINOR_VERSION > 0
14
#define FLEX_BETA
15
#endif
16
17
#ifdef yy_create_buffer
18
#define re_yy_create_buffer_ALREADY_DEFINED
19
#else
20
0
#define yy_create_buffer re_yy_create_buffer
21
#endif
22
23
#ifdef yy_delete_buffer
24
#define re_yy_delete_buffer_ALREADY_DEFINED
25
#else
26
0
#define yy_delete_buffer re_yy_delete_buffer
27
#endif
28
29
#ifdef yy_scan_buffer
30
#define re_yy_scan_buffer_ALREADY_DEFINED
31
#else
32
0
#define yy_scan_buffer re_yy_scan_buffer
33
#endif
34
35
#ifdef yy_scan_string
36
#define re_yy_scan_string_ALREADY_DEFINED
37
#else
38
0
#define yy_scan_string re_yy_scan_string
39
#endif
40
41
#ifdef yy_scan_bytes
42
#define re_yy_scan_bytes_ALREADY_DEFINED
43
#else
44
0
#define yy_scan_bytes re_yy_scan_bytes
45
#endif
46
47
#ifdef yy_init_buffer
48
#define re_yy_init_buffer_ALREADY_DEFINED
49
#else
50
0
#define yy_init_buffer re_yy_init_buffer
51
#endif
52
53
#ifdef yy_flush_buffer
54
#define re_yy_flush_buffer_ALREADY_DEFINED
55
#else
56
0
#define yy_flush_buffer re_yy_flush_buffer
57
#endif
58
59
#ifdef yy_load_buffer_state
60
#define re_yy_load_buffer_state_ALREADY_DEFINED
61
#else
62
0
#define yy_load_buffer_state re_yy_load_buffer_state
63
#endif
64
65
#ifdef yy_switch_to_buffer
66
#define re_yy_switch_to_buffer_ALREADY_DEFINED
67
#else
68
0
#define yy_switch_to_buffer re_yy_switch_to_buffer
69
#endif
70
71
#ifdef yypush_buffer_state
72
#define re_yypush_buffer_state_ALREADY_DEFINED
73
#else
74
#define yypush_buffer_state re_yypush_buffer_state
75
#endif
76
77
#ifdef yypop_buffer_state
78
#define re_yypop_buffer_state_ALREADY_DEFINED
79
#else
80
0
#define yypop_buffer_state re_yypop_buffer_state
81
#endif
82
83
#ifdef yyensure_buffer_stack
84
#define re_yyensure_buffer_stack_ALREADY_DEFINED
85
#else
86
0
#define yyensure_buffer_stack re_yyensure_buffer_stack
87
#endif
88
89
#ifdef yylex
90
#define re_yylex_ALREADY_DEFINED
91
#else
92
#define yylex re_yylex
93
#endif
94
95
#ifdef yyrestart
96
#define re_yyrestart_ALREADY_DEFINED
97
#else
98
0
#define yyrestart re_yyrestart
99
#endif
100
101
#ifdef yylex_init
102
#define re_yylex_init_ALREADY_DEFINED
103
#else
104
0
#define yylex_init re_yylex_init
105
#endif
106
107
#ifdef yylex_init_extra
108
#define re_yylex_init_extra_ALREADY_DEFINED
109
#else
110
#define yylex_init_extra re_yylex_init_extra
111
#endif
112
113
#ifdef yylex_destroy
114
#define re_yylex_destroy_ALREADY_DEFINED
115
#else
116
0
#define yylex_destroy re_yylex_destroy
117
#endif
118
119
#ifdef yyget_debug
120
#define re_yyget_debug_ALREADY_DEFINED
121
#else
122
#define yyget_debug re_yyget_debug
123
#endif
124
125
#ifdef yyset_debug
126
#define re_yyset_debug_ALREADY_DEFINED
127
#else
128
#define yyset_debug re_yyset_debug
129
#endif
130
131
#ifdef yyget_extra
132
#define re_yyget_extra_ALREADY_DEFINED
133
#else
134
#define yyget_extra re_yyget_extra
135
#endif
136
137
#ifdef yyset_extra
138
#define re_yyset_extra_ALREADY_DEFINED
139
#else
140
0
#define yyset_extra re_yyset_extra
141
#endif
142
143
#ifdef yyget_in
144
#define re_yyget_in_ALREADY_DEFINED
145
#else
146
#define yyget_in re_yyget_in
147
#endif
148
149
#ifdef yyset_in
150
#define re_yyset_in_ALREADY_DEFINED
151
#else
152
#define yyset_in re_yyset_in
153
#endif
154
155
#ifdef yyget_out
156
#define re_yyget_out_ALREADY_DEFINED
157
#else
158
#define yyget_out re_yyget_out
159
#endif
160
161
#ifdef yyset_out
162
#define re_yyset_out_ALREADY_DEFINED
163
#else
164
#define yyset_out re_yyset_out
165
#endif
166
167
#ifdef yyget_leng
168
#define re_yyget_leng_ALREADY_DEFINED
169
#else
170
#define yyget_leng re_yyget_leng
171
#endif
172
173
#ifdef yyget_text
174
#define re_yyget_text_ALREADY_DEFINED
175
#else
176
#define yyget_text re_yyget_text
177
#endif
178
179
#ifdef yyget_lineno
180
#define re_yyget_lineno_ALREADY_DEFINED
181
#else
182
#define yyget_lineno re_yyget_lineno
183
#endif
184
185
#ifdef yyset_lineno
186
#define re_yyset_lineno_ALREADY_DEFINED
187
#else
188
#define yyset_lineno re_yyset_lineno
189
#endif
190
191
#ifdef yyget_column
192
#define re_yyget_column_ALREADY_DEFINED
193
#else
194
#define yyget_column re_yyget_column
195
#endif
196
197
#ifdef yyset_column
198
#define re_yyset_column_ALREADY_DEFINED
199
#else
200
#define yyset_column re_yyset_column
201
#endif
202
203
#ifdef yywrap
204
#define re_yywrap_ALREADY_DEFINED
205
#else
206
0
#define yywrap re_yywrap
207
#endif
208
209
#ifdef yyget_lval
210
#define re_yyget_lval_ALREADY_DEFINED
211
#else
212
#define yyget_lval re_yyget_lval
213
#endif
214
215
#ifdef yyset_lval
216
#define re_yyset_lval_ALREADY_DEFINED
217
#else
218
#define yyset_lval re_yyset_lval
219
#endif
220
221
#ifdef yyalloc
222
#define re_yyalloc_ALREADY_DEFINED
223
#else
224
0
#define yyalloc re_yyalloc
225
#endif
226
227
#ifdef yyrealloc
228
#define re_yyrealloc_ALREADY_DEFINED
229
#else
230
0
#define yyrealloc re_yyrealloc
231
#endif
232
233
#ifdef yyfree
234
#define re_yyfree_ALREADY_DEFINED
235
#else
236
0
#define yyfree re_yyfree
237
#endif
238
239
/* First, we deal with  platform-specific or compiler-specific issues. */
240
241
/* begin standard C headers. */
242
#include <stdio.h>
243
#include <string.h>
244
#include <errno.h>
245
#include <stdlib.h>
246
247
/* end standard C headers. */
248
249
/* flex integer type definitions */
250
251
#ifndef FLEXINT_H
252
#define FLEXINT_H
253
254
/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
255
256
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
257
258
/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
259
 * if you want the limit (max/min) macros for int types. 
260
 */
261
#ifndef __STDC_LIMIT_MACROS
262
#define __STDC_LIMIT_MACROS 1
263
#endif
264
265
#include <inttypes.h>
266
typedef int8_t flex_int8_t;
267
typedef uint8_t flex_uint8_t;
268
typedef int16_t flex_int16_t;
269
typedef uint16_t flex_uint16_t;
270
typedef int32_t flex_int32_t;
271
typedef uint32_t flex_uint32_t;
272
#else
273
typedef signed char flex_int8_t;
274
typedef short int flex_int16_t;
275
typedef int flex_int32_t;
276
typedef unsigned char flex_uint8_t; 
277
typedef unsigned short int flex_uint16_t;
278
typedef unsigned int flex_uint32_t;
279
280
/* Limits of integral types. */
281
#ifndef INT8_MIN
282
#define INT8_MIN               (-128)
283
#endif
284
#ifndef INT16_MIN
285
#define INT16_MIN              (-32767-1)
286
#endif
287
#ifndef INT32_MIN
288
#define INT32_MIN              (-2147483647-1)
289
#endif
290
#ifndef INT8_MAX
291
#define INT8_MAX               (127)
292
#endif
293
#ifndef INT16_MAX
294
#define INT16_MAX              (32767)
295
#endif
296
#ifndef INT32_MAX
297
#define INT32_MAX              (2147483647)
298
#endif
299
#ifndef UINT8_MAX
300
#define UINT8_MAX              (255U)
301
#endif
302
#ifndef UINT16_MAX
303
#define UINT16_MAX             (65535U)
304
#endif
305
#ifndef UINT32_MAX
306
#define UINT32_MAX             (4294967295U)
307
#endif
308
309
#ifndef SIZE_MAX
310
#define SIZE_MAX               (~(size_t)0)
311
#endif
312
313
#endif /* ! C99 */
314
315
#endif /* ! FLEXINT_H */
316
317
/* begin standard C++ headers. */
318
319
/* TODO: this is always defined, so inline it */
320
#define yyconst const
321
322
#if defined(__GNUC__) && __GNUC__ >= 3
323
#define yynoreturn __attribute__((__noreturn__))
324
#else
325
#define yynoreturn
326
#endif
327
328
/* Returned upon end-of-file. */
329
0
#define YY_NULL 0
330
331
/* Promotes a possibly negative, possibly signed char to an
332
 *   integer in range [0..255] for use as an array index.
333
 */
334
0
#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
335
336
/* An opaque pointer. */
337
#ifndef YY_TYPEDEF_YY_SCANNER_T
338
#define YY_TYPEDEF_YY_SCANNER_T
339
typedef void* yyscan_t;
340
#endif
341
342
/* For convenience, these vars (plus the bison vars far below)
343
   are macros in the reentrant scanner. */
344
0
#define yyin yyg->yyin_r
345
0
#define yyout yyg->yyout_r
346
0
#define yyextra yyg->yyextra_r
347
0
#define yyleng yyg->yyleng_r
348
0
#define yytext yyg->yytext_r
349
0
#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
350
0
#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
351
0
#define yy_flex_debug yyg->yy_flex_debug_r
352
353
/* Enter a start condition.  This macro really ought to take a parameter,
354
 * but we do it the disgusting crufty way forced on us by the ()-less
355
 * definition of BEGIN.
356
 */
357
0
#define BEGIN yyg->yy_start = 1 + 2 *
358
/* Translate the current start state into a value that can be later handed
359
 * to BEGIN to return to the state.  The YYSTATE alias is for lex
360
 * compatibility.
361
 */
362
#define YY_START ((yyg->yy_start - 1) / 2)
363
#define YYSTATE YY_START
364
/* Action number for EOF rule of a given start state. */
365
0
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
366
/* Special action meaning "start processing a new file". */
367
0
#define YY_NEW_FILE yyrestart( yyin , yyscanner )
368
0
#define YY_END_OF_BUFFER_CHAR 0
369
370
/* Size of default input buffer. */
371
#ifndef YY_BUF_SIZE
372
#ifdef __ia64__
373
/* On IA-64, the buffer size is 16k, not 8k.
374
 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
375
 * Ditto for the __ia64__ case accordingly.
376
 */
377
#define YY_BUF_SIZE 32768
378
#else
379
0
#define YY_BUF_SIZE 16384
380
#endif /* __ia64__ */
381
#endif
382
383
/* The state buf must be large enough to hold one state per character in the main buffer.
384
 */
385
#define YY_STATE_BUF_SIZE   ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
386
387
#ifndef YY_TYPEDEF_YY_BUFFER_STATE
388
#define YY_TYPEDEF_YY_BUFFER_STATE
389
typedef struct yy_buffer_state *YY_BUFFER_STATE;
390
#endif
391
392
#ifndef YY_TYPEDEF_YY_SIZE_T
393
#define YY_TYPEDEF_YY_SIZE_T
394
typedef size_t yy_size_t;
395
#endif
396
397
0
#define EOB_ACT_CONTINUE_SCAN 0
398
0
#define EOB_ACT_END_OF_FILE 1
399
0
#define EOB_ACT_LAST_MATCH 2
400
    
401
    /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires
402
     *       access to the local variable yy_act. Since yyless() is a macro, it would break
403
     *       existing scanners that call yyless() from OUTSIDE yylex.
404
     *       One obvious solution it to make yy_act a global. I tried that, and saw
405
     *       a 5% performance hit in a non-yylineno scanner, because yy_act is
406
     *       normally declared as a register variable-- so it is not worth it.
407
     */
408
    #define  YY_LESS_LINENO(n) \
409
            do { \
410
                int yyl;\
411
                for ( yyl = n; yyl < yyleng; ++yyl )\
412
                    if ( yytext[yyl] == '\n' )\
413
                        --yylineno;\
414
            }while(0)
415
    #define YY_LINENO_REWIND_TO(dst) \
416
            do {\
417
                const char *p;\
418
                for ( p = yy_cp-1; p >= (dst); --p)\
419
                    if ( *p == '\n' )\
420
                        --yylineno;\
421
            }while(0)
422
    
423
/* Return all but the first "n" matched characters back to the input stream. */
424
#define yyless(n) \
425
  do \
426
    { \
427
    /* Undo effects of setting up yytext. */ \
428
        int yyless_macro_arg = (n); \
429
        YY_LESS_LINENO(yyless_macro_arg);\
430
    *yy_cp = yyg->yy_hold_char; \
431
    YY_RESTORE_YY_MORE_OFFSET \
432
    yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
433
    YY_DO_BEFORE_ACTION; /* set up yytext again */ \
434
    } \
435
  while ( 0 )
436
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
437
438
#ifndef YY_STRUCT_YY_BUFFER_STATE
439
#define YY_STRUCT_YY_BUFFER_STATE
440
struct yy_buffer_state
441
  {
442
  FILE *yy_input_file;
443
444
  char *yy_ch_buf;    /* input buffer */
445
  char *yy_buf_pos;   /* current position in input buffer */
446
447
  /* Size of input buffer in bytes, not including room for EOB
448
   * characters.
449
   */
450
  int yy_buf_size;
451
452
  /* Number of characters read into yy_ch_buf, not including EOB
453
   * characters.
454
   */
455
  int yy_n_chars;
456
457
  /* Whether we "own" the buffer - i.e., we know we created it,
458
   * and can realloc() it to grow it, and should free() it to
459
   * delete it.
460
   */
461
  int yy_is_our_buffer;
462
463
  /* Whether this is an "interactive" input source; if so, and
464
   * if we're using stdio for input, then we want to use getc()
465
   * instead of fread(), to make sure we stop fetching input after
466
   * each newline.
467
   */
468
  int yy_is_interactive;
469
470
  /* Whether we're considered to be at the beginning of a line.
471
   * If so, '^' rules will be active on the next match, otherwise
472
   * not.
473
   */
474
  int yy_at_bol;
475
476
    int yy_bs_lineno; /**< The line count. */
477
    int yy_bs_column; /**< The column count. */
478
479
  /* Whether to try to fill the input buffer when we reach the
480
   * end of it.
481
   */
482
  int yy_fill_buffer;
483
484
  int yy_buffer_status;
485
486
0
#define YY_BUFFER_NEW 0
487
0
#define YY_BUFFER_NORMAL 1
488
  /* When an EOF's been seen but there's still some text to process
489
   * then we mark the buffer as YY_EOF_PENDING, to indicate that we
490
   * shouldn't try reading from the input source any more.  We might
491
   * still have a bunch of tokens to match, though, because of
492
   * possible backing-up.
493
   *
494
   * When we actually see the EOF, we change the status to "new"
495
   * (via yyrestart()), so that the user can continue scanning by
496
   * just pointing yyin at a new input file.
497
   */
498
0
#define YY_BUFFER_EOF_PENDING 2
499
500
  };
501
#endif /* !YY_STRUCT_YY_BUFFER_STATE */
502
503
/* We provide macros for accessing buffer states in case in the
504
 * future we want to put the buffer states in a more general
505
 * "scanner state".
506
 *
507
 * Returns the top of the stack, or NULL.
508
 */
509
0
#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
510
0
                          ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
511
0
                          : NULL)
512
/* Same as previous macro, but useful when we know that the buffer stack is not
513
 * NULL or when we need an lvalue. For internal use only.
514
 */
515
0
#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
516
517
void yyrestart ( FILE *input_file , yyscan_t yyscanner );
518
void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
519
YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
520
void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
521
void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
522
void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
523
void yypop_buffer_state ( yyscan_t yyscanner );
524
525
static void yyensure_buffer_stack ( yyscan_t yyscanner );
526
static void yy_load_buffer_state ( yyscan_t yyscanner );
527
static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner );
528
#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner)
529
530
YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
531
YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
532
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
533
534
void *yyalloc ( yy_size_t , yyscan_t yyscanner );
535
void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
536
void yyfree ( void * , yyscan_t yyscanner );
537
538
#define yy_new_buffer yy_create_buffer
539
#define yy_set_interactive(is_interactive) \
540
  { \
541
  if ( ! YY_CURRENT_BUFFER ){ \
542
        yyensure_buffer_stack (yyscanner); \
543
    YY_CURRENT_BUFFER_LVALUE =    \
544
            yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \
545
  } \
546
  YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
547
  }
548
#define yy_set_bol(at_bol) \
549
  { \
550
  if ( ! YY_CURRENT_BUFFER ){\
551
        yyensure_buffer_stack (yyscanner); \
552
    YY_CURRENT_BUFFER_LVALUE =    \
553
            yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \
554
  } \
555
  YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
556
  }
557
#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
558
559
/* Begin user sect3 */
560
561
0
#define re_yywrap(yyscanner) (/*CONSTCOND*/1)
562
#define YY_SKIP_YYWRAP
563
typedef flex_uint8_t YY_CHAR;
564
565
typedef int yy_state_type;
566
567
0
#define yytext_ptr yytext_r
568
569
static yy_state_type yy_get_previous_state ( yyscan_t yyscanner );
570
static yy_state_type yy_try_NUL_trans ( yy_state_type current_state  , yyscan_t yyscanner);
571
static int yy_get_next_buffer ( yyscan_t yyscanner );
572
static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
573
574
/* Done after the current pattern has been matched and before the
575
 * corresponding action - sets up yytext.
576
 */
577
#define YY_DO_BEFORE_ACTION \
578
0
  yyg->yytext_ptr = yy_bp; \
579
0
  yyleng = (int) (yy_cp - yy_bp); \
580
0
  yyg->yy_hold_char = *yy_cp; \
581
0
  *yy_cp = '\0'; \
582
0
  yyg->yy_c_buf_p = yy_cp;
583
#define YY_NUM_RULES 29
584
0
#define YY_END_OF_BUFFER 30
585
/* This struct is not used in this scanner,
586
   but its presence is necessary. */
587
struct yy_trans_info
588
  {
589
  flex_int32_t yy_verify;
590
  flex_int32_t yy_nxt;
591
  };
592
static const flex_int16_t yy_accept[47] =
593
    {   0,
594
        0,    0,    0,    0,   30,    7,    7,   28,    6,   17,
595
        7,   27,   29,   26,   18,    5,    3,   16,   15,   13,
596
       11,    9,   14,   12,   10,    8,    0,    0,    0,    0,
597
        0,   25,   23,   21,   24,   22,   20,    0,    4,    0,
598
        0,    1,    2,   19,    0,    0
599
    } ;
600
601
static const YY_CHAR yy_ec[256] =
602
    {   0,
603
        1,    1,    1,    1,    1,    1,    1,    1,    1,    2,
604
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
605
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
606
        1,    3,    1,    1,    1,    4,    1,    1,    1,    4,
607
        4,    4,    4,    5,    6,    4,    1,    7,    7,    7,
608
        7,    7,    7,    7,    7,    7,    7,    1,    1,    1,
609
        1,    1,    4,    1,    8,    9,    8,   10,    8,    8,
610
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
611
        1,    1,   11,    1,    1,    1,   12,    1,    1,    1,
612
       13,   14,   15,   16,    1,    1,    8,   17,    8,   18,
613
614
        8,    8,    1,    1,    1,    1,    1,    1,    1,    1,
615
        1,    1,    1,    1,   19,    1,    1,    1,   20,   21,
616
        1,    1,   22,    4,   23,    1,    1,    1,    1,    1,
617
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
618
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
619
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
620
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
621
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
622
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
623
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
624
625
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
626
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
627
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
628
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
629
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
630
        1,    1,    1,    1,    1
631
    } ;
632
633
static const YY_CHAR yy_meta[24] =
634
    {   0,
635
        1,    2,    1,    1,    1,    3,    4,    4,    4,    4,
636
        1,    1,    1,    1,    5,    1,    4,    4,    1,    1,
637
        1,    1,    1
638
    } ;
639
640
static const flex_int16_t yy_base[53] =
641
    {   0,
642
        0,   21,    3,    5,   53,  112,  112,  112,   11,   37,
643
        3,   45,   44,   48,  112,  112,   27,   33,  112,  112,
644
      112,  112,  112,  112,  112,  112,    6,   29,   67,    0,
645
       33,   32,   27,   25,   24,   23,   18,   15,  112,   38,
646
        5,  112,  112,  112,    0,  112,   90,   95,  100,  105,
647
      107,   11
648
    } ;
649
650
static const flex_int16_t yy_def[53] =
651
    {   0,
652
       47,   47,   48,   48,   46,   46,   46,   46,   46,   46,
653
       46,   46,   46,   49,   46,   46,   46,   46,   46,   46,
654
       46,   46,   46,   46,   46,   46,   46,   46,   46,   50,
655
       46,   46,   46,   46,   46,   46,   46,   51,   46,   46,
656
       46,   46,   46,   46,   52,    0,   46,   46,   46,   46,
657
       46,   46
658
    } ;
659
660
static const flex_int16_t yy_nxt[136] =
661
    {   0,
662
       46,    7,   46,    8,   13,   27,   13,   28,   27,   29,
663
       28,   41,    9,   10,   31,    8,   14,   15,   14,   15,
664
       30,   11,    7,   30,    8,   16,   17,   42,   30,   30,
665
       30,   40,   30,    9,   10,   41,    8,   30,   30,   18,
666
       40,   39,   11,   18,   41,   19,   20,   21,   22,   30,
667
       30,   42,   46,   23,   24,   25,   26,   32,   33,   34,
668
       42,   46,   46,   46,   46,   35,   36,   37,   38,   27,
669
       46,   28,   46,   29,   46,   46,   46,   46,   46,   46,
670
       46,   46,   46,   46,   46,   46,   46,   46,   46,   43,
671
        6,    6,    6,    6,    6,   12,   12,   12,   12,   12,
672
673
       31,   46,   31,   31,   31,   44,   44,   44,   44,   45,
674
       45,    5,   46,   46,   46,   46,   46,   46,   46,   46,
675
       46,   46,   46,   46,   46,   46,   46,   46,   46,   46,
676
       46,   46,   46,   46,   46
677
    } ;
678
679
static const flex_int16_t yy_chk[136] =
680
    {   0,
681
        0,    1,    0,    1,    3,   11,    4,   11,   27,   11,
682
       27,   41,    1,    1,   52,    1,    3,    3,    4,    4,
683
       38,    1,    2,   37,    2,    9,    9,   41,   36,   35,
684
       34,   28,   33,    2,    2,   28,    2,   32,   31,   18,
685
       40,   17,    2,   10,   40,   10,   10,   10,   10,   13,
686
       12,   28,    5,   10,   10,   10,   10,   14,   14,   14,
687
       40,    0,    0,    0,    0,   14,   14,   14,   14,   29,
688
        0,   29,    0,   29,    0,    0,    0,    0,    0,    0,
689
        0,    0,    0,    0,    0,    0,    0,    0,    0,   29,
690
       47,   47,   47,   47,   47,   48,   48,   48,   48,   48,
691
692
       49,    0,   49,   49,   49,   50,   50,   50,   50,   51,
693
       51,   46,   46,   46,   46,   46,   46,   46,   46,   46,
694
       46,   46,   46,   46,   46,   46,   46,   46,   46,   46,
695
       46,   46,   46,   46,   46
696
    } ;
697
698
/* Table of booleans, true if rule could match eol. */
699
static const flex_int32_t yy_rule_can_match_eol[30] =
700
    {   0,
701
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
702
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,     };
703
704
/* The intent behind this definition is that it'll catch
705
 * any uses of REJECT which flex missed.
706
 */
707
#define REJECT reject_used_but_not_detected
708
#define yymore() yymore_used_but_not_detected
709
0
#define YY_MORE_ADJ 0
710
#define YY_RESTORE_YY_MORE_OFFSET
711
#line 1 "libyara/re_lexer.l"
712
/*
713
Copyright (c) 2013. The YARA Authors. All Rights Reserved.
714
715
Redistribution and use in source and binary forms, with or without modification,
716
are permitted provided that the following conditions are met:
717
718
1. Redistributions of source code must retain the above copyright notice, this
719
list of conditions and the following disclaimer.
720
721
2. Redistributions in binary form must reproduce the above copyright notice,
722
this list of conditions and the following disclaimer in the documentation and/or
723
other materials provided with the distribution.
724
725
3. Neither the name of the copyright holder nor the names of its contributors
726
may be used to endorse or promote products derived from this software without
727
specific prior written permission.
728
729
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
730
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
731
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
732
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
733
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
734
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
735
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
736
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
737
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
738
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
739
*/
740
/* Lexical analyzer for regular expressions */
741
#line 33 "libyara/re_lexer.l"
742
743
/* Disable warnings for unused functions in this file.
744
745
As we redefine YY_FATAL_ERROR macro to use our own function re_yyfatal, the
746
yy_fatal_error function generated by Flex is not actually used, causing a
747
compiler warning. Flex doesn't offer any options to remove the yy_fatal_error
748
function. When they include something like %option noyy_fatal_error as they do
749
with noyywrap then we can remove this pragma.
750
*/
751
752
#ifdef __GNUC__
753
#pragma GCC diagnostic ignored "-Wunused-function"
754
#endif
755
756
#include <assert.h>
757
#include <setjmp.h>
758
759
#include <yara/globals.h>
760
#include <yara/utils.h>
761
#include <yara/error.h>
762
#include <yara/limits.h>
763
#include <yara/mem.h>
764
#include <yara/re.h>
765
#include <yara/re_lexer.h>
766
#include <yara/threading.h>
767
#include <yara/strutils.h>
768
#include <yara/compiler.h>
769
770
771
#ifdef _WIN32
772
#define snprintf _snprintf
773
#define strtoll  _strtoi64
774
#endif
775
776
// Bitmap with 1 bit for each of the 256 characters in the ASCII table. The bit
777
// is set to 1 if the corresponding character is alphanumeric or 0 if otherwise.
778
static uint8_t word_chars[] = {
779
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03,
780
    0xFE, 0xFF, 0xFF, 0x87, 0xFE, 0xFF, 0xFF, 0x07,
781
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
782
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
783
784
// Bitmap with 1 bit for each of the 256 characters in the ASCII table. The bit
785
// is set to 1 if the corresponding character is considered a space. Space
786
// characters include horizontal and vertical tabs, carriage return, new line
787
// and form feed (\t, \v, \r, \n, \f).
788
static uint8_t space_chars[] = {
789
    0x00, 0x3E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
790
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
791
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
792
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
793
794
int escaped_char_value(
795
    char* text,
796
    uint8_t* value,
797
    bool strict_escape);
798
799
int read_escaped_char(
800
    yyscan_t yyscanner,
801
    uint8_t* escaped_char,
802
    bool strict_escape);
803
804
#line 804 "libyara/re_lexer.c"
805
#define YY_NO_UNISTD_H 1
806
807
#line 807 "libyara/re_lexer.c"
808
809
0
#define INITIAL 0
810
0
#define char_class 1
811
812
#ifndef YY_NO_UNISTD_H
813
/* Special case for "unistd.h", since it is non-ANSI. We include it way
814
 * down here because we want the user's section 1 to have been scanned first.
815
 * The user has a chance to override it with an option.
816
 */
817
#include <unistd.h>
818
#endif
819
820
#ifndef YY_EXTRA_TYPE
821
#define YY_EXTRA_TYPE void *
822
#endif
823
824
/* Holds the entire state of the reentrant scanner. */
825
struct yyguts_t
826
    {
827
828
    /* User-defined. Not touched by flex. */
829
    YY_EXTRA_TYPE yyextra_r;
830
831
    /* The rest are the same as the globals declared in the non-reentrant scanner. */
832
    FILE *yyin_r, *yyout_r;
833
    size_t yy_buffer_stack_top; /**< index of top of stack. */
834
    size_t yy_buffer_stack_max; /**< capacity of stack. */
835
    YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
836
    char yy_hold_char;
837
    int yy_n_chars;
838
    int yyleng_r;
839
    char *yy_c_buf_p;
840
    int yy_init;
841
    int yy_start;
842
    int yy_did_buffer_switch_on_eof;
843
    int yy_start_stack_ptr;
844
    int yy_start_stack_depth;
845
    int *yy_start_stack;
846
    yy_state_type yy_last_accepting_state;
847
    char* yy_last_accepting_cpos;
848
849
    int yylineno_r;
850
    int yy_flex_debug_r;
851
852
    char *yytext_r;
853
    int yy_more_flag;
854
    int yy_more_len;
855
856
    YYSTYPE * yylval_r;
857
858
    }; /* end struct yyguts_t */
859
860
static int yy_init_globals ( yyscan_t yyscanner );
861
862
    /* This must go here because YYSTYPE and YYLTYPE are included
863
     * from bison output in section 1.*/
864
0
    #    define yylval yyg->yylval_r
865
    
866
int yylex_init (yyscan_t* scanner);
867
868
int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner);
869
870
/* Accessor methods to globals.
871
   These are made visible to non-reentrant scanners for convenience. */
872
873
int yylex_destroy ( yyscan_t yyscanner );
874
875
int yyget_debug ( yyscan_t yyscanner );
876
877
void yyset_debug ( int debug_flag , yyscan_t yyscanner );
878
879
YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
880
881
void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
882
883
FILE *yyget_in ( yyscan_t yyscanner );
884
885
void yyset_in  ( FILE * _in_str , yyscan_t yyscanner );
886
887
FILE *yyget_out ( yyscan_t yyscanner );
888
889
void yyset_out  ( FILE * _out_str , yyscan_t yyscanner );
890
891
      int yyget_leng ( yyscan_t yyscanner );
892
893
char *yyget_text ( yyscan_t yyscanner );
894
895
int yyget_lineno ( yyscan_t yyscanner );
896
897
void yyset_lineno ( int _line_number , yyscan_t yyscanner );
898
899
int yyget_column  ( yyscan_t yyscanner );
900
901
void yyset_column ( int _column_no , yyscan_t yyscanner );
902
903
YYSTYPE * yyget_lval ( yyscan_t yyscanner );
904
905
void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner );
906
907
/* Macros after this point can all be overridden by user definitions in
908
 * section 1.
909
 */
910
911
#ifndef YY_SKIP_YYWRAP
912
#ifdef __cplusplus
913
extern "C" int yywrap ( yyscan_t yyscanner );
914
#else
915
extern int yywrap ( yyscan_t yyscanner );
916
#endif
917
#endif
918
919
#ifndef YY_NO_UNPUT
920
    
921
#endif
922
923
#ifndef yytext_ptr
924
static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
925
#endif
926
927
#ifdef YY_NEED_STRLEN
928
static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
929
#endif
930
931
#ifndef YY_NO_INPUT
932
#ifdef __cplusplus
933
static int yyinput ( yyscan_t yyscanner );
934
#else
935
static int input ( yyscan_t yyscanner );
936
#endif
937
938
#endif
939
940
/* Amount of stuff to slurp up with each read. */
941
#ifndef YY_READ_BUF_SIZE
942
#ifdef __ia64__
943
/* On IA-64, the buffer size is 16k, not 8k */
944
#define YY_READ_BUF_SIZE 16384
945
#else
946
0
#define YY_READ_BUF_SIZE 8192
947
#endif /* __ia64__ */
948
#endif
949
950
/* Copy whatever the last rule matched to the standard output. */
951
#ifndef ECHO
952
/* This used to be an fputs(), but since the string might contain NUL's,
953
 * we now use fwrite().
954
 */
955
#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
956
#endif
957
958
/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
959
 * is returned in "result".
960
 */
961
#ifndef YY_INPUT
962
#define YY_INPUT(buf,result,max_size) \
963
0
  if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
964
0
    { \
965
0
    int c = '*'; \
966
0
    int n; \
967
0
    for ( n = 0; n < max_size && \
968
0
           (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
969
0
      buf[n] = (char) c; \
970
0
    if ( c == '\n' ) \
971
0
      buf[n++] = (char) c; \
972
0
    if ( c == EOF && ferror( yyin ) ) \
973
0
      YY_FATAL_ERROR( "input in flex scanner failed" ); \
974
0
    result = n; \
975
0
    } \
976
0
  else \
977
0
    { \
978
0
    errno=0; \
979
0
    while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
980
0
      { \
981
0
      if( errno != EINTR) \
982
0
        { \
983
0
        YY_FATAL_ERROR( "input in flex scanner failed" ); \
984
0
        break; \
985
0
        } \
986
0
      errno=0; \
987
0
      clearerr(yyin); \
988
0
      } \
989
0
    }\
990
\
991
992
#endif
993
994
/* No semi-colon after return; correct usage is to write "yyterminate();" -
995
 * we don't want an extra ';' after the "return" because that will cause
996
 * some compilers to complain about unreachable statements.
997
 */
998
#ifndef yyterminate
999
0
#define yyterminate() return YY_NULL
1000
#endif
1001
1002
/* Number of entries by which start-condition stack grows. */
1003
#ifndef YY_START_STACK_INCR
1004
#define YY_START_STACK_INCR 25
1005
#endif
1006
1007
/* Report a fatal error. */
1008
#ifndef YY_FATAL_ERROR
1009
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
1010
#endif
1011
1012
/* end tables serialization structures and prototypes */
1013
1014
/* Default declaration of generated scanner - a define so the user can
1015
 * easily add parameters.
1016
 */
1017
#ifndef YY_DECL
1018
#define YY_DECL_IS_OURS 1
1019
1020
extern int yylex \
1021
               (YYSTYPE * yylval_param , yyscan_t yyscanner);
1022
1023
#define YY_DECL int yylex \
1024
               (YYSTYPE * yylval_param , yyscan_t yyscanner)
1025
#endif /* !YY_DECL */
1026
1027
/* Code executed at the beginning of each rule, after yytext and yyleng
1028
 * have been set up.
1029
 */
1030
#ifndef YY_USER_ACTION
1031
#define YY_USER_ACTION
1032
#endif
1033
1034
/* Code executed at the end of each rule. */
1035
#ifndef YY_BREAK
1036
0
#define YY_BREAK /*LINTED*/break;
1037
#endif
1038
1039
#define YY_RULE_SETUP \
1040
  YY_USER_ACTION
1041
1042
/** The main scanner function which does all the work.
1043
 */
1044
YY_DECL
1045
0
{
1046
0
  yy_state_type yy_current_state;
1047
0
  char *yy_cp, *yy_bp;
1048
0
  int yy_act;
1049
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1050
1051
0
    yylval = yylval_param;
1052
1053
0
  if ( !yyg->yy_init )
1054
0
    {
1055
0
    yyg->yy_init = 1;
1056
1057
#ifdef YY_USER_INIT
1058
    YY_USER_INIT;
1059
#endif
1060
1061
0
    if ( ! yyg->yy_start )
1062
0
      yyg->yy_start = 1; /* first start state */
1063
1064
0
    if ( ! yyin )
1065
0
      yyin = stdin;
1066
1067
0
    if ( ! yyout )
1068
0
      yyout = stdout;
1069
1070
0
    if ( ! YY_CURRENT_BUFFER ) {
1071
0
      yyensure_buffer_stack (yyscanner);
1072
0
      YY_CURRENT_BUFFER_LVALUE =
1073
0
        yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
1074
0
    }
1075
1076
0
    yy_load_buffer_state( yyscanner );
1077
0
    }
1078
1079
0
  {
1080
0
#line 115 "libyara/re_lexer.l"
1081
1082
1083
0
#line 1083 "libyara/re_lexer.c"
1084
1085
0
  while ( /*CONSTCOND*/1 )    /* loops until end-of-file is reached */
1086
0
    {
1087
0
    yy_cp = yyg->yy_c_buf_p;
1088
1089
    /* Support of yytext. */
1090
0
    *yy_cp = yyg->yy_hold_char;
1091
1092
    /* yy_bp points to the position in yy_ch_buf of the start of
1093
     * the current run.
1094
     */
1095
0
    yy_bp = yy_cp;
1096
1097
0
    yy_current_state = yyg->yy_start;
1098
0
yy_match:
1099
0
    do
1100
0
      {
1101
0
      YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
1102
0
      if ( yy_accept[yy_current_state] )
1103
0
        {
1104
0
        yyg->yy_last_accepting_state = yy_current_state;
1105
0
        yyg->yy_last_accepting_cpos = yy_cp;
1106
0
        }
1107
0
      while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1108
0
        {
1109
0
        yy_current_state = (int) yy_def[yy_current_state];
1110
0
        if ( yy_current_state >= 47 )
1111
0
          yy_c = yy_meta[yy_c];
1112
0
        }
1113
0
      yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1114
0
      ++yy_cp;
1115
0
      }
1116
0
    while ( yy_current_state != 46 );
1117
0
    yy_cp = yyg->yy_last_accepting_cpos;
1118
0
    yy_current_state = yyg->yy_last_accepting_state;
1119
1120
0
yy_find_action:
1121
0
    yy_act = yy_accept[yy_current_state];
1122
1123
0
    YY_DO_BEFORE_ACTION;
1124
1125
0
    if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
1126
0
      {
1127
0
      int yyl;
1128
0
      for ( yyl = 0; yyl < yyleng; ++yyl )
1129
0
        if ( yytext[yyl] == '\n' )
1130
          
1131
0
    do{ yylineno++;
1132
0
        yycolumn=0;
1133
0
    }while(0)
1134
0
;
1135
0
      }
1136
1137
0
do_action:  /* This label is used only to access EOF actions. */
1138
1139
0
    switch ( yy_act )
1140
0
  { /* beginning of action switch */
1141
0
      case 0: /* must back up */
1142
      /* undo the effects of YY_DO_BEFORE_ACTION */
1143
0
      *yy_cp = yyg->yy_hold_char;
1144
0
      yy_cp = yyg->yy_last_accepting_cpos;
1145
0
      yy_current_state = yyg->yy_last_accepting_state;
1146
0
      goto yy_find_action;
1147
1148
0
case 1:
1149
0
YY_RULE_SETUP
1150
0
#line 117 "libyara/re_lexer.l"
1151
0
{
1152
1153
  // Examples: {3,8} {3, 8}, {3 ,8} {3 , 8} {0,5} {,5} {7,}
1154
1155
  // strtoll is used instead of atoi because atoi has undefined behaviour for
1156
  // numbers that don't fit in an int. Numbers too large for a long long are
1157
  // clamped to LLONG_MAX by strtoll, which is still caught by the RE_MAX_RANGE
1158
  // check below.
1159
1160
0
  long long hi_bound;
1161
0
  long long lo_bound = strtoll(yytext + 1, NULL, 10);
1162
1163
0
  char* comma = strchr(yytext, ',');
1164
0
  char* hi_bound_ptr = comma + 1;
1165
1166
  // Skip spaces after the comma, if any.
1167
0
  while (*hi_bound_ptr == ' ') hi_bound_ptr++;
1168
1169
0
  if (*hi_bound_ptr == '}')
1170
0
    hi_bound = RE_MAX_RANGE;
1171
0
  else
1172
0
    hi_bound = strtoll(hi_bound_ptr, NULL, 10);
1173
1174
0
  if (hi_bound > RE_MAX_RANGE)
1175
0
  {
1176
0
    yyerror(yyscanner, lex_env, "repeat interval too large");
1177
0
    yyterminate();
1178
0
  }
1179
1180
0
  if (hi_bound < lo_bound)
1181
0
  {
1182
0
    yyerror(yyscanner, lex_env, "bad repeat interval");
1183
0
    yyterminate();
1184
0
  }
1185
1186
0
  yylval->range = (uint32_t) ((hi_bound << 16) | lo_bound);
1187
1188
0
  return _RANGE_;
1189
0
}
1190
0
  YY_BREAK
1191
0
case 2:
1192
0
YY_RULE_SETUP
1193
0
#line 158 "libyara/re_lexer.l"
1194
0
{
1195
1196
  // Example: {10}
1197
1198
0
  long long value = strtoll(yytext + 1, NULL, 10);
1199
1200
0
  if (value > RE_MAX_RANGE)
1201
0
  {
1202
0
    yyerror(yyscanner, lex_env, "repeat interval too large");
1203
0
    yyterminate();
1204
0
  }
1205
1206
0
  yylval->range = (uint32_t) ((value << 16) | value);
1207
1208
0
  return _RANGE_;
1209
0
}
1210
0
  YY_BREAK
1211
0
case 3:
1212
0
YY_RULE_SETUP
1213
0
#line 176 "libyara/re_lexer.l"
1214
0
{
1215
1216
  // Start of a negated character class. Example: [^abcd]
1217
1218
0
  BEGIN(char_class);
1219
0
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1220
0
  LEX_ENV->re_class.negated = true;
1221
0
}
1222
0
  YY_BREAK
1223
0
case 4:
1224
0
YY_RULE_SETUP
1225
0
#line 185 "libyara/re_lexer.l"
1226
0
{
1227
1228
  // Start of character negated class containing a ].
1229
  // Example: [^]abc] this must be interpreted as a class
1230
  // not matching ], a, b, nor c
1231
1232
0
  BEGIN(char_class);
1233
0
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1234
0
  LEX_ENV->re_class.negated = true;
1235
0
  LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8;
1236
0
}
1237
0
  YY_BREAK
1238
0
case 5:
1239
0
YY_RULE_SETUP
1240
0
#line 198 "libyara/re_lexer.l"
1241
0
{
1242
1243
  // Start of character class containing a ].
1244
  // Example: []abc] this must be interpreted as a class
1245
  // matching ], a, b, or c.
1246
1247
0
  BEGIN(char_class);
1248
0
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1249
0
  LEX_ENV->re_class.negated = false;
1250
0
  LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8;
1251
0
}
1252
0
  YY_BREAK
1253
0
case 6:
1254
0
YY_RULE_SETUP
1255
0
#line 211 "libyara/re_lexer.l"
1256
0
{
1257
1258
  // Start of character class. Example: [abcd]
1259
1260
0
  BEGIN(char_class);
1261
0
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1262
0
  LEX_ENV->re_class.negated = false;
1263
0
}
1264
0
  YY_BREAK
1265
0
case 7:
1266
/* rule 7 can match eol */
1267
0
YY_RULE_SETUP
1268
0
#line 221 "libyara/re_lexer.l"
1269
0
{
1270
1271
  // Any non-special character is passed as a CHAR token to the scanner.
1272
1273
0
  yylval->integer = yytext[0];
1274
0
  return _CHAR_;
1275
0
}
1276
0
  YY_BREAK
1277
0
case 8:
1278
0
YY_RULE_SETUP
1279
0
#line 230 "libyara/re_lexer.l"
1280
0
{
1281
0
  return _WORD_CHAR_;
1282
0
}
1283
0
  YY_BREAK
1284
0
case 9:
1285
0
YY_RULE_SETUP
1286
0
#line 235 "libyara/re_lexer.l"
1287
0
{
1288
0
  return _NON_WORD_CHAR_;
1289
0
}
1290
0
  YY_BREAK
1291
0
case 10:
1292
0
YY_RULE_SETUP
1293
0
#line 240 "libyara/re_lexer.l"
1294
0
{
1295
0
  return _SPACE_;
1296
0
}
1297
0
  YY_BREAK
1298
0
case 11:
1299
0
YY_RULE_SETUP
1300
0
#line 245 "libyara/re_lexer.l"
1301
0
{
1302
0
  return _NON_SPACE_;
1303
0
}
1304
0
  YY_BREAK
1305
0
case 12:
1306
0
YY_RULE_SETUP
1307
0
#line 250 "libyara/re_lexer.l"
1308
0
{
1309
0
  return _DIGIT_;
1310
0
}
1311
0
  YY_BREAK
1312
0
case 13:
1313
0
YY_RULE_SETUP
1314
0
#line 255 "libyara/re_lexer.l"
1315
0
{
1316
0
  return _NON_DIGIT_;
1317
0
}
1318
0
  YY_BREAK
1319
0
case 14:
1320
0
YY_RULE_SETUP
1321
0
#line 260 "libyara/re_lexer.l"
1322
0
{
1323
0
  return _WORD_BOUNDARY_;
1324
0
}
1325
0
  YY_BREAK
1326
0
case 15:
1327
0
YY_RULE_SETUP
1328
0
#line 264 "libyara/re_lexer.l"
1329
0
{
1330
0
  return _NON_WORD_BOUNDARY_;
1331
0
}
1332
0
  YY_BREAK
1333
0
case 16:
1334
0
YY_RULE_SETUP
1335
0
#line 269 "libyara/re_lexer.l"
1336
0
{
1337
1338
0
  yyerror(yyscanner, lex_env, "backreferences are not allowed");
1339
0
  yyterminate();
1340
0
}
1341
0
  YY_BREAK
1342
0
case 17:
1343
0
YY_RULE_SETUP
1344
0
#line 276 "libyara/re_lexer.l"
1345
0
{
1346
1347
0
  uint8_t c;
1348
0
  int return_code;
1349
1350
0
  return_code = read_escaped_char(yyscanner, &c, LEX_ENV->strict_escape);
1351
0
  if (return_code == VALID_ESCAPE_SEQUENCE)
1352
0
  {
1353
0
    yylval->integer = c;
1354
0
    return _CHAR_;
1355
0
  }
1356
0
  else if (return_code == UNKNOWN_ESCAPE_SEQUENCE)
1357
0
  {
1358
0
    yywarning(yyscanner, lex_env, "unknown escape sequence");
1359
0
    yylval->integer = c;
1360
0
    return _CHAR_;
1361
0
  }
1362
0
  else
1363
0
  {
1364
0
    yyerror(yyscanner, lex_env, "illegal escape sequence");
1365
0
    yyterminate();
1366
0
  }
1367
0
}
1368
0
  YY_BREAK
1369
0
case 18:
1370
0
YY_RULE_SETUP
1371
0
#line 301 "libyara/re_lexer.l"
1372
0
{
1373
1374
  // End of character class.
1375
0
  yylval->re_class = (RE_CLASS*) yr_malloc(sizeof(RE_CLASS));
1376
0
  memcpy(yylval->re_class->bitmap, LEX_ENV->re_class.bitmap, 32);
1377
1378
0
  yylval->re_class->negated = LEX_ENV->re_class.negated;
1379
1380
0
  BEGIN(INITIAL);
1381
0
  return _CLASS_;
1382
0
}
1383
0
  YY_BREAK
1384
0
case 19:
1385
/* rule 19 can match eol */
1386
0
YY_RULE_SETUP
1387
0
#line 315 "libyara/re_lexer.l"
1388
0
{
1389
1390
  // A range inside a character class. The regexp is...
1391
  //
1392
  //   ( \x{hex_digit}{2}    Hex digit (i.e: \x01) ...
1393
  //   | \.                  ...or any escaped character (i.e. \\, \-) ...
1394
  //   | [^]\]               ...or any character except ] and \ ...
1395
  //   )
1396
  //   -                     ... followed by -
1397
  //   [^]]                  ... followed by any character except ]
1398
  //
1399
  // Some examples:
1400
  //
1401
  //  [abc0-9]
1402
  //      ^-^ matching range 0-9
1403
  //
1404
  //  [a-za-]
1405
  //   ^-^- matching range a-z
1406
  //
1407
  //  [\.-a]
1408
  //   ^--^- matching range \.-a
1409
  //
1410
1411
0
  uint16_t c;
1412
0
  uint8_t start = yytext[0];
1413
0
  uint8_t end = yytext[2];
1414
1415
0
  if (start == '\\')
1416
0
  {
1417
0
    if (!escaped_char_value(yytext, &start, LEX_ENV->strict_escape))
1418
0
    {
1419
0
      yyerror(yyscanner, lex_env, "illegal escape sequence");
1420
0
      yyterminate();
1421
0
    }
1422
1423
0
    if (yytext[1] == 'x')
1424
0
      end = yytext[5];
1425
0
    else
1426
0
      end = yytext[3];
1427
0
  }
1428
1429
0
  if (end == '\\')
1430
0
  {
1431
0
    if (!read_escaped_char(yyscanner, &end, LEX_ENV->strict_escape))
1432
0
    {
1433
0
      yyerror(yyscanner, lex_env, "illegal escape sequence");
1434
0
      yyterminate();
1435
0
    }
1436
0
  }
1437
1438
0
  if (end < start)
1439
0
  {
1440
0
    yyerror(yyscanner, lex_env, "bad character range");
1441
0
    yyterminate();
1442
0
  }
1443
1444
0
  for (c = start; c <= end; c++)
1445
0
  {
1446
0
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1447
0
  }
1448
0
}
1449
0
  YY_BREAK
1450
0
case 20:
1451
0
YY_RULE_SETUP
1452
0
#line 378 "libyara/re_lexer.l"
1453
0
{
1454
1455
0
  for (int i = 0; i < 32; i++)
1456
0
    LEX_ENV->re_class.bitmap[i] |= word_chars[i];
1457
0
}
1458
0
  YY_BREAK
1459
0
case 21:
1460
0
YY_RULE_SETUP
1461
0
#line 385 "libyara/re_lexer.l"
1462
0
{
1463
1464
0
  for (int i = 0; i < 32; i++)
1465
0
    LEX_ENV->re_class.bitmap[i] |= ~word_chars[i];
1466
0
}
1467
0
  YY_BREAK
1468
0
case 22:
1469
0
YY_RULE_SETUP
1470
0
#line 392 "libyara/re_lexer.l"
1471
0
{
1472
1473
0
  for (int i = 0; i < 32; i++)
1474
0
    LEX_ENV->re_class.bitmap[i] |= space_chars[i];
1475
0
}
1476
0
  YY_BREAK
1477
0
case 23:
1478
0
YY_RULE_SETUP
1479
0
#line 399 "libyara/re_lexer.l"
1480
0
{
1481
1482
0
  for (int i = 0; i < 32; i++)
1483
0
    LEX_ENV->re_class.bitmap[i] |= ~space_chars[i];
1484
0
}
1485
0
  YY_BREAK
1486
0
case 24:
1487
0
YY_RULE_SETUP
1488
0
#line 406 "libyara/re_lexer.l"
1489
0
{
1490
1491
0
  for (char c = '0'; c <= '9'; c++)
1492
0
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1493
0
}
1494
0
  YY_BREAK
1495
0
case 25:
1496
0
YY_RULE_SETUP
1497
0
#line 413 "libyara/re_lexer.l"
1498
0
{
1499
1500
0
  for (int i = 0; i < 32; i++)
1501
0
  {
1502
    // digits 0-7 are in the sixth byte of the vector, let that byte alone
1503
0
    if (i == 6)
1504
0
      continue;
1505
1506
    // digits 8 and 9 are the lowest two bits in the seventh byte of the
1507
    // vector, let those bits alone.
1508
0
    if (i == 7)
1509
0
      LEX_ENV->re_class.bitmap[i] |= 0xFC;
1510
0
    else
1511
0
      LEX_ENV->re_class.bitmap[i] = 0xFF;
1512
0
  }
1513
0
}
1514
0
  YY_BREAK
1515
0
case 26:
1516
0
YY_RULE_SETUP
1517
0
#line 431 "libyara/re_lexer.l"
1518
0
{
1519
1520
0
  uint8_t c;
1521
0
  int return_code;
1522
1523
0
  return_code = read_escaped_char(yyscanner, &c, LEX_ENV->strict_escape);
1524
0
  if (return_code == VALID_ESCAPE_SEQUENCE)
1525
0
  {
1526
0
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1527
0
  }
1528
0
  else if (return_code == UNKNOWN_ESCAPE_SEQUENCE)
1529
0
  {
1530
0
    yywarning(yyscanner, lex_env, "unknown escape sequence");
1531
0
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1532
0
  }
1533
0
  else
1534
0
  {
1535
0
    yyerror(yyscanner, lex_env, "illegal escape sequence");
1536
0
    yyterminate();
1537
0
  }
1538
0
}
1539
0
  YY_BREAK
1540
0
case 27:
1541
0
YY_RULE_SETUP
1542
0
#line 454 "libyara/re_lexer.l"
1543
0
{
1544
1545
0
  if (yytext[0] >= 32 && yytext[0] < 127)
1546
0
  {
1547
    // A character class (i.e: [0-9a-f]) is represented by a 256-bits vector,
1548
    // here we set to 1 the vector's bit corresponding to the input character.
1549
1550
0
    LEX_ENV->re_class.bitmap[yytext[0] / 8] |= 1 << yytext[0] % 8;
1551
0
  }
1552
0
  else
1553
0
  {
1554
0
    yyerror(yyscanner, lex_env, "non-ascii character");
1555
0
    yyterminate();
1556
0
  }
1557
0
}
1558
0
  YY_BREAK
1559
0
case YY_STATE_EOF(char_class):
1560
0
#line 471 "libyara/re_lexer.l"
1561
0
{
1562
1563
  // End of regexp reached while scanning a character class.
1564
1565
0
  yyerror(yyscanner, lex_env, "missing terminating ] for character class");
1566
0
  yyterminate();
1567
0
}
1568
0
  YY_BREAK
1569
0
case 28:
1570
0
YY_RULE_SETUP
1571
0
#line 480 "libyara/re_lexer.l"
1572
0
{
1573
1574
0
  if (yytext[0] >= 32 && yytext[0] < 127)
1575
0
  {
1576
0
    return yytext[0];
1577
0
  }
1578
0
  else
1579
0
  {
1580
0
    yyerror(yyscanner, lex_env, "non-ascii character");
1581
0
    yyterminate();
1582
0
  }
1583
0
}
1584
0
  YY_BREAK
1585
0
case YY_STATE_EOF(INITIAL):
1586
0
#line 494 "libyara/re_lexer.l"
1587
0
{
1588
1589
0
  yyterminate();
1590
0
}
1591
0
  YY_BREAK
1592
0
case 29:
1593
0
YY_RULE_SETUP
1594
0
#line 499 "libyara/re_lexer.l"
1595
0
ECHO;
1596
0
  YY_BREAK
1597
0
#line 1597 "libyara/re_lexer.c"
1598
1599
0
  case YY_END_OF_BUFFER:
1600
0
    {
1601
    /* Amount of text matched not including the EOB char. */
1602
0
    int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
1603
1604
    /* Undo the effects of YY_DO_BEFORE_ACTION. */
1605
0
    *yy_cp = yyg->yy_hold_char;
1606
0
    YY_RESTORE_YY_MORE_OFFSET
1607
1608
0
    if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1609
0
      {
1610
      /* We're scanning a new file or input source.  It's
1611
       * possible that this happened because the user
1612
       * just pointed yyin at a new source and called
1613
       * yylex().  If so, then we have to assure
1614
       * consistency between YY_CURRENT_BUFFER and our
1615
       * globals.  Here is the right place to do so, because
1616
       * this is the first action (other than possibly a
1617
       * back-up) that will match for the new input source.
1618
       */
1619
0
      yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1620
0
      YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1621
0
      YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1622
0
      }
1623
1624
    /* Note that here we test for yy_c_buf_p "<=" to the position
1625
     * of the first EOB in the buffer, since yy_c_buf_p will
1626
     * already have been incremented past the NUL character
1627
     * (since all states make transitions on EOB to the
1628
     * end-of-buffer state).  Contrast this with the test
1629
     * in input().
1630
     */
1631
0
    if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1632
0
      { /* This was really a NUL. */
1633
0
      yy_state_type yy_next_state;
1634
1635
0
      yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
1636
1637
0
      yy_current_state = yy_get_previous_state( yyscanner );
1638
1639
      /* Okay, we're now positioned to make the NUL
1640
       * transition.  We couldn't have
1641
       * yy_get_previous_state() go ahead and do it
1642
       * for us because it doesn't know how to deal
1643
       * with the possibility of jamming (and we don't
1644
       * want to build jamming into it because then it
1645
       * will run more slowly).
1646
       */
1647
1648
0
      yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
1649
1650
0
      yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1651
1652
0
      if ( yy_next_state )
1653
0
        {
1654
        /* Consume the NUL. */
1655
0
        yy_cp = ++yyg->yy_c_buf_p;
1656
0
        yy_current_state = yy_next_state;
1657
0
        goto yy_match;
1658
0
        }
1659
1660
0
      else
1661
0
        {
1662
0
        yy_cp = yyg->yy_last_accepting_cpos;
1663
0
        yy_current_state = yyg->yy_last_accepting_state;
1664
0
        goto yy_find_action;
1665
0
        }
1666
0
      }
1667
1668
0
    else switch ( yy_get_next_buffer( yyscanner ) )
1669
0
      {
1670
0
      case EOB_ACT_END_OF_FILE:
1671
0
        {
1672
0
        yyg->yy_did_buffer_switch_on_eof = 0;
1673
1674
0
        if ( yywrap( yyscanner ) )
1675
0
          {
1676
          /* Note: because we've taken care in
1677
           * yy_get_next_buffer() to have set up
1678
           * yytext, we can now set up
1679
           * yy_c_buf_p so that if some total
1680
           * hoser (like flex itself) wants to
1681
           * call the scanner after we return the
1682
           * YY_NULL, it'll still work - another
1683
           * YY_NULL will get returned.
1684
           */
1685
0
          yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
1686
1687
0
          yy_act = YY_STATE_EOF(YY_START);
1688
0
          goto do_action;
1689
0
          }
1690
1691
0
        else
1692
0
          {
1693
0
          if ( ! yyg->yy_did_buffer_switch_on_eof )
1694
0
            YY_NEW_FILE;
1695
0
          }
1696
0
        break;
1697
0
        }
1698
1699
0
      case EOB_ACT_CONTINUE_SCAN:
1700
0
        yyg->yy_c_buf_p =
1701
0
          yyg->yytext_ptr + yy_amount_of_matched_text;
1702
1703
0
        yy_current_state = yy_get_previous_state( yyscanner );
1704
1705
0
        yy_cp = yyg->yy_c_buf_p;
1706
0
        yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1707
0
        goto yy_match;
1708
1709
0
      case EOB_ACT_LAST_MATCH:
1710
0
        yyg->yy_c_buf_p =
1711
0
        &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
1712
1713
0
        yy_current_state = yy_get_previous_state( yyscanner );
1714
1715
0
        yy_cp = yyg->yy_c_buf_p;
1716
0
        yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1717
0
        goto yy_find_action;
1718
0
      }
1719
0
    break;
1720
0
    }
1721
1722
0
  default:
1723
0
    YY_FATAL_ERROR(
1724
0
      "fatal flex scanner internal error--no action found" );
1725
0
  } /* end of action switch */
1726
0
    } /* end of scanning one token */
1727
0
  } /* end of user's declarations */
1728
0
} /* end of yylex */
1729
1730
/* yy_get_next_buffer - try to read in a new buffer
1731
 *
1732
 * Returns a code representing an action:
1733
 *  EOB_ACT_LAST_MATCH -
1734
 *  EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1735
 *  EOB_ACT_END_OF_FILE - end of file
1736
 */
1737
static int yy_get_next_buffer (yyscan_t yyscanner)
1738
0
{
1739
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1740
0
  char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1741
0
  char *source = yyg->yytext_ptr;
1742
0
  int number_to_move, i;
1743
0
  int ret_val;
1744
1745
0
  if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
1746
0
    YY_FATAL_ERROR(
1747
0
    "fatal flex scanner internal error--end of buffer missed" );
1748
1749
0
  if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1750
0
    { /* Don't try to fill the buffer, so this is an EOF. */
1751
0
    if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
1752
0
      {
1753
      /* We matched a single character, the EOB, so
1754
       * treat this as a final EOF.
1755
       */
1756
0
      return EOB_ACT_END_OF_FILE;
1757
0
      }
1758
1759
0
    else
1760
0
      {
1761
      /* We matched some text prior to the EOB, first
1762
       * process it.
1763
       */
1764
0
      return EOB_ACT_LAST_MATCH;
1765
0
      }
1766
0
    }
1767
1768
  /* Try to read more data. */
1769
1770
  /* First move last chars to start of buffer. */
1771
0
  number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
1772
1773
0
  for ( i = 0; i < number_to_move; ++i )
1774
0
    *(dest++) = *(source++);
1775
1776
0
  if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1777
    /* don't do the read, it's not guaranteed to return an EOF,
1778
     * just force an EOF
1779
     */
1780
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
1781
1782
0
  else
1783
0
    {
1784
0
      int num_to_read =
1785
0
      YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1786
1787
0
    while ( num_to_read <= 0 )
1788
0
      { /* Not enough room in the buffer - grow it. */
1789
1790
      /* just a shorter name for the current buffer */
1791
0
      YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1792
1793
0
      int yy_c_buf_p_offset =
1794
0
        (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
1795
1796
0
      if ( b->yy_is_our_buffer )
1797
0
        {
1798
0
        int new_size = b->yy_buf_size * 2;
1799
1800
0
        if ( new_size <= 0 )
1801
0
          b->yy_buf_size += b->yy_buf_size / 8;
1802
0
        else
1803
0
          b->yy_buf_size *= 2;
1804
1805
0
        b->yy_ch_buf = (char *)
1806
          /* Include room in for 2 EOB chars. */
1807
0
          yyrealloc( (void *) b->yy_ch_buf,
1808
0
               (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
1809
0
        }
1810
0
      else
1811
        /* Can't grow it, we don't own it. */
1812
0
        b->yy_ch_buf = NULL;
1813
1814
0
      if ( ! b->yy_ch_buf )
1815
0
        YY_FATAL_ERROR(
1816
0
        "fatal error - scanner input buffer overflow" );
1817
1818
0
      yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
1819
1820
0
      num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1821
0
            number_to_move - 1;
1822
1823
0
      }
1824
1825
0
    if ( num_to_read > YY_READ_BUF_SIZE )
1826
0
      num_to_read = YY_READ_BUF_SIZE;
1827
1828
    /* Read in more data. */
1829
0
    YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1830
0
      yyg->yy_n_chars, num_to_read );
1831
1832
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1833
0
    }
1834
1835
0
  if ( yyg->yy_n_chars == 0 )
1836
0
    {
1837
0
    if ( number_to_move == YY_MORE_ADJ )
1838
0
      {
1839
0
      ret_val = EOB_ACT_END_OF_FILE;
1840
0
      yyrestart( yyin  , yyscanner);
1841
0
      }
1842
1843
0
    else
1844
0
      {
1845
0
      ret_val = EOB_ACT_LAST_MATCH;
1846
0
      YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1847
0
        YY_BUFFER_EOF_PENDING;
1848
0
      }
1849
0
    }
1850
1851
0
  else
1852
0
    ret_val = EOB_ACT_CONTINUE_SCAN;
1853
1854
0
  if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1855
    /* Extend the array by 50%, plus the number we really need. */
1856
0
    int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
1857
0
    YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
1858
0
      (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
1859
0
    if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1860
0
      YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1861
    /* "- 2" to take care of EOB's */
1862
0
    YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
1863
0
  }
1864
1865
0
  yyg->yy_n_chars += number_to_move;
1866
0
  YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
1867
0
  YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
1868
1869
0
  yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1870
1871
0
  return ret_val;
1872
0
}
1873
1874
/* yy_get_previous_state - get the state just before the EOB char was reached */
1875
1876
    static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
1877
0
{
1878
0
  yy_state_type yy_current_state;
1879
0
  char *yy_cp;
1880
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1881
1882
0
  yy_current_state = yyg->yy_start;
1883
1884
0
  for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
1885
0
    {
1886
0
    YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1887
0
    if ( yy_accept[yy_current_state] )
1888
0
      {
1889
0
      yyg->yy_last_accepting_state = yy_current_state;
1890
0
      yyg->yy_last_accepting_cpos = yy_cp;
1891
0
      }
1892
0
    while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1893
0
      {
1894
0
      yy_current_state = (int) yy_def[yy_current_state];
1895
0
      if ( yy_current_state >= 47 )
1896
0
        yy_c = yy_meta[yy_c];
1897
0
      }
1898
0
    yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1899
0
    }
1900
1901
0
  return yy_current_state;
1902
0
}
1903
1904
/* yy_try_NUL_trans - try to make a transition on the NUL character
1905
 *
1906
 * synopsis
1907
 *  next_state = yy_try_NUL_trans( current_state );
1908
 */
1909
    static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state , yyscan_t yyscanner)
1910
0
{
1911
0
  int yy_is_jam;
1912
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
1913
0
  char *yy_cp = yyg->yy_c_buf_p;
1914
1915
0
  YY_CHAR yy_c = 1;
1916
0
  if ( yy_accept[yy_current_state] )
1917
0
    {
1918
0
    yyg->yy_last_accepting_state = yy_current_state;
1919
0
    yyg->yy_last_accepting_cpos = yy_cp;
1920
0
    }
1921
0
  while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1922
0
    {
1923
0
    yy_current_state = (int) yy_def[yy_current_state];
1924
0
    if ( yy_current_state >= 47 )
1925
0
      yy_c = yy_meta[yy_c];
1926
0
    }
1927
0
  yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1928
0
  yy_is_jam = (yy_current_state == 46);
1929
1930
0
  (void)yyg;
1931
0
  return yy_is_jam ? 0 : yy_current_state;
1932
0
}
1933
1934
#ifndef YY_NO_UNPUT
1935
1936
#endif
1937
1938
#ifndef YY_NO_INPUT
1939
#ifdef __cplusplus
1940
    static int yyinput (yyscan_t yyscanner)
1941
#else
1942
    static int input  (yyscan_t yyscanner)
1943
#endif
1944
1945
0
{
1946
0
  int c;
1947
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1948
1949
0
  *yyg->yy_c_buf_p = yyg->yy_hold_char;
1950
1951
0
  if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
1952
0
    {
1953
    /* yy_c_buf_p now points to the character we want to return.
1954
     * If this occurs *before* the EOB characters, then it's a
1955
     * valid NUL; if not, then we've hit the end of the buffer.
1956
     */
1957
0
    if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1958
      /* This was really a NUL. */
1959
0
      *yyg->yy_c_buf_p = '\0';
1960
1961
0
    else
1962
0
      { /* need more input */
1963
0
      int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
1964
0
      ++yyg->yy_c_buf_p;
1965
1966
0
      switch ( yy_get_next_buffer( yyscanner ) )
1967
0
        {
1968
0
        case EOB_ACT_LAST_MATCH:
1969
          /* This happens because yy_g_n_b()
1970
           * sees that we've accumulated a
1971
           * token and flags that we need to
1972
           * try matching the token before
1973
           * proceeding.  But for input(),
1974
           * there's no matching to consider.
1975
           * So convert the EOB_ACT_LAST_MATCH
1976
           * to EOB_ACT_END_OF_FILE.
1977
           */
1978
1979
          /* Reset buffer status. */
1980
0
          yyrestart( yyin , yyscanner);
1981
1982
          /*FALLTHROUGH*/
1983
1984
0
        case EOB_ACT_END_OF_FILE:
1985
0
          {
1986
0
          if ( yywrap( yyscanner ) )
1987
0
            return 0;
1988
1989
0
          if ( ! yyg->yy_did_buffer_switch_on_eof )
1990
0
            YY_NEW_FILE;
1991
#ifdef __cplusplus
1992
          return yyinput(yyscanner);
1993
#else
1994
0
          return input(yyscanner);
1995
0
#endif
1996
0
          }
1997
1998
0
        case EOB_ACT_CONTINUE_SCAN:
1999
0
          yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
2000
0
          break;
2001
0
        }
2002
0
      }
2003
0
    }
2004
2005
0
  c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
2006
0
  *yyg->yy_c_buf_p = '\0';  /* preserve yytext */
2007
0
  yyg->yy_hold_char = *++yyg->yy_c_buf_p;
2008
2009
0
  if ( c == '\n' )
2010
    
2011
0
    do{ yylineno++;
2012
0
        yycolumn=0;
2013
0
    }while(0)
2014
0
;
2015
2016
0
  return c;
2017
0
}
2018
#endif  /* ifndef YY_NO_INPUT */
2019
2020
/** Immediately switch to a different input stream.
2021
 * @param input_file A readable stream.
2022
 * @param yyscanner The scanner object.
2023
 * @note This function does not reset the start condition to @c INITIAL .
2024
 */
2025
    void yyrestart  (FILE * input_file , yyscan_t yyscanner)
2026
0
{
2027
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2028
2029
0
  if ( ! YY_CURRENT_BUFFER ){
2030
0
        yyensure_buffer_stack (yyscanner);
2031
0
    YY_CURRENT_BUFFER_LVALUE =
2032
0
            yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
2033
0
  }
2034
2035
0
  yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
2036
0
  yy_load_buffer_state( yyscanner );
2037
0
}
2038
2039
/** Switch to a different input buffer.
2040
 * @param new_buffer The new input buffer.
2041
 * @param yyscanner The scanner object.
2042
 */
2043
    void yy_switch_to_buffer  (YY_BUFFER_STATE  new_buffer , yyscan_t yyscanner)
2044
0
{
2045
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2046
2047
  /* TODO. We should be able to replace this entire function body
2048
   * with
2049
   *    yypop_buffer_state();
2050
   *    yypush_buffer_state(new_buffer);
2051
     */
2052
0
  yyensure_buffer_stack (yyscanner);
2053
0
  if ( YY_CURRENT_BUFFER == new_buffer )
2054
0
    return;
2055
2056
0
  if ( YY_CURRENT_BUFFER )
2057
0
    {
2058
    /* Flush out information for old buffer. */
2059
0
    *yyg->yy_c_buf_p = yyg->yy_hold_char;
2060
0
    YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
2061
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
2062
0
    }
2063
2064
0
  YY_CURRENT_BUFFER_LVALUE = new_buffer;
2065
0
  yy_load_buffer_state( yyscanner );
2066
2067
  /* We don't actually know whether we did this switch during
2068
   * EOF (yywrap()) processing, but the only time this flag
2069
   * is looked at is after yywrap() is called, so it's safe
2070
   * to go ahead and always set it.
2071
   */
2072
0
  yyg->yy_did_buffer_switch_on_eof = 1;
2073
0
}
2074
2075
static void yy_load_buffer_state  (yyscan_t yyscanner)
2076
0
{
2077
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2078
0
  yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
2079
0
  yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
2080
0
  yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
2081
0
  yyg->yy_hold_char = *yyg->yy_c_buf_p;
2082
0
}
2083
2084
/** Allocate and initialize an input buffer state.
2085
 * @param file A readable stream.
2086
 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
2087
 * @param yyscanner The scanner object.
2088
 * @return the allocated buffer state.
2089
 */
2090
    YY_BUFFER_STATE yy_create_buffer  (FILE * file, int  size , yyscan_t yyscanner)
2091
0
{
2092
0
  YY_BUFFER_STATE b;
2093
    
2094
0
  b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
2095
0
  if ( ! b )
2096
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
2097
2098
0
  b->yy_buf_size = size;
2099
2100
  /* yy_ch_buf has to be 2 characters longer than the size given because
2101
   * we need to put in 2 end-of-buffer characters.
2102
   */
2103
0
  b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
2104
0
  if ( ! b->yy_ch_buf )
2105
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
2106
2107
0
  b->yy_is_our_buffer = 1;
2108
2109
0
  yy_init_buffer( b, file , yyscanner);
2110
2111
0
  return b;
2112
0
}
2113
2114
/** Destroy the buffer.
2115
 * @param b a buffer created with yy_create_buffer()
2116
 * @param yyscanner The scanner object.
2117
 */
2118
    void yy_delete_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
2119
0
{
2120
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2121
2122
0
  if ( ! b )
2123
0
    return;
2124
2125
0
  if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
2126
0
    YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
2127
2128
0
  if ( b->yy_is_our_buffer )
2129
0
    yyfree( (void *) b->yy_ch_buf , yyscanner );
2130
2131
0
  yyfree( (void *) b , yyscanner );
2132
0
}
2133
2134
/* Initializes or reinitializes a buffer.
2135
 * This function is sometimes called more than once on the same buffer,
2136
 * such as during a yyrestart() or at EOF.
2137
 */
2138
    static void yy_init_buffer  (YY_BUFFER_STATE  b, FILE * file , yyscan_t yyscanner)
2139
2140
0
{
2141
0
  int oerrno = errno;
2142
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2143
2144
0
  yy_flush_buffer( b , yyscanner);
2145
2146
0
  b->yy_input_file = file;
2147
0
  b->yy_fill_buffer = 1;
2148
2149
    /* If b is the current buffer, then yy_init_buffer was _probably_
2150
     * called from yyrestart() or through yy_get_next_buffer.
2151
     * In that case, we don't want to reset the lineno or column.
2152
     */
2153
0
    if (b != YY_CURRENT_BUFFER){
2154
0
        b->yy_bs_lineno = 1;
2155
0
        b->yy_bs_column = 0;
2156
0
    }
2157
2158
0
        b->yy_is_interactive = 0;
2159
    
2160
0
  errno = oerrno;
2161
0
}
2162
2163
/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
2164
 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
2165
 * @param yyscanner The scanner object.
2166
 */
2167
    void yy_flush_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
2168
0
{
2169
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2170
0
  if ( ! b )
2171
0
    return;
2172
2173
0
  b->yy_n_chars = 0;
2174
2175
  /* We always need two end-of-buffer characters.  The first causes
2176
   * a transition to the end-of-buffer state.  The second causes
2177
   * a jam in that state.
2178
   */
2179
0
  b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
2180
0
  b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
2181
2182
0
  b->yy_buf_pos = &b->yy_ch_buf[0];
2183
2184
0
  b->yy_at_bol = 1;
2185
0
  b->yy_buffer_status = YY_BUFFER_NEW;
2186
2187
0
  if ( b == YY_CURRENT_BUFFER )
2188
0
    yy_load_buffer_state( yyscanner );
2189
0
}
2190
2191
/** Pushes the new state onto the stack. The new state becomes
2192
 *  the current state. This function will allocate the stack
2193
 *  if necessary.
2194
 *  @param new_buffer The new state.
2195
 *  @param yyscanner The scanner object.
2196
 */
2197
void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
2198
0
{
2199
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2200
0
  if (new_buffer == NULL)
2201
0
    return;
2202
2203
0
  yyensure_buffer_stack(yyscanner);
2204
2205
  /* This block is copied from yy_switch_to_buffer. */
2206
0
  if ( YY_CURRENT_BUFFER )
2207
0
    {
2208
    /* Flush out information for old buffer. */
2209
0
    *yyg->yy_c_buf_p = yyg->yy_hold_char;
2210
0
    YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
2211
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
2212
0
    }
2213
2214
  /* Only push if top exists. Otherwise, replace top. */
2215
0
  if (YY_CURRENT_BUFFER)
2216
0
    yyg->yy_buffer_stack_top++;
2217
0
  YY_CURRENT_BUFFER_LVALUE = new_buffer;
2218
2219
  /* copied from yy_switch_to_buffer. */
2220
0
  yy_load_buffer_state( yyscanner );
2221
0
  yyg->yy_did_buffer_switch_on_eof = 1;
2222
0
}
2223
2224
/** Removes and deletes the top of the stack, if present.
2225
 *  The next element becomes the new top.
2226
 *  @param yyscanner The scanner object.
2227
 */
2228
void yypop_buffer_state (yyscan_t yyscanner)
2229
0
{
2230
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2231
0
  if (!YY_CURRENT_BUFFER)
2232
0
    return;
2233
2234
0
  yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner);
2235
0
  YY_CURRENT_BUFFER_LVALUE = NULL;
2236
0
  if (yyg->yy_buffer_stack_top > 0)
2237
0
    --yyg->yy_buffer_stack_top;
2238
2239
0
  if (YY_CURRENT_BUFFER) {
2240
0
    yy_load_buffer_state( yyscanner );
2241
0
    yyg->yy_did_buffer_switch_on_eof = 1;
2242
0
  }
2243
0
}
2244
2245
/* Allocates the stack if it does not exist.
2246
 *  Guarantees space for at least one push.
2247
 */
2248
static void yyensure_buffer_stack (yyscan_t yyscanner)
2249
0
{
2250
0
  yy_size_t num_to_alloc;
2251
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2252
2253
0
  if (!yyg->yy_buffer_stack) {
2254
2255
    /* First allocation is just for 2 elements, since we don't know if this
2256
     * scanner will even need a stack. We use 2 instead of 1 to avoid an
2257
     * immediate realloc on the next call.
2258
         */
2259
0
      num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
2260
0
    yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
2261
0
                (num_to_alloc * sizeof(struct yy_buffer_state*)
2262
0
                , yyscanner);
2263
0
    if ( ! yyg->yy_buffer_stack )
2264
0
      YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2265
2266
0
    memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
2267
2268
0
    yyg->yy_buffer_stack_max = num_to_alloc;
2269
0
    yyg->yy_buffer_stack_top = 0;
2270
0
    return;
2271
0
  }
2272
2273
0
  if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
2274
2275
    /* Increase the buffer to prepare for a possible push. */
2276
0
    yy_size_t grow_size = 8 /* arbitrary grow size */;
2277
2278
0
    num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
2279
0
    yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc
2280
0
                (yyg->yy_buffer_stack,
2281
0
                num_to_alloc * sizeof(struct yy_buffer_state*)
2282
0
                , yyscanner);
2283
0
    if ( ! yyg->yy_buffer_stack )
2284
0
      YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2285
2286
    /* zero only the new slots.*/
2287
0
    memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
2288
0
    yyg->yy_buffer_stack_max = num_to_alloc;
2289
0
  }
2290
0
}
2291
2292
/** Setup the input buffer state to scan directly from a user-specified character buffer.
2293
 * @param base the character buffer
2294
 * @param size the size in bytes of the character buffer
2295
 * @param yyscanner The scanner object.
2296
 * @return the newly allocated buffer state object.
2297
 */
2298
YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size , yyscan_t yyscanner)
2299
0
{
2300
0
  YY_BUFFER_STATE b;
2301
    
2302
0
  if ( size < 2 ||
2303
0
       base[size-2] != YY_END_OF_BUFFER_CHAR ||
2304
0
       base[size-1] != YY_END_OF_BUFFER_CHAR )
2305
    /* They forgot to leave room for the EOB's. */
2306
0
    return NULL;
2307
2308
0
  b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
2309
0
  if ( ! b )
2310
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
2311
2312
0
  b->yy_buf_size = (int) (size - 2);  /* "- 2" to take care of EOB's */
2313
0
  b->yy_buf_pos = b->yy_ch_buf = base;
2314
0
  b->yy_is_our_buffer = 0;
2315
0
  b->yy_input_file = NULL;
2316
0
  b->yy_n_chars = b->yy_buf_size;
2317
0
  b->yy_is_interactive = 0;
2318
0
  b->yy_at_bol = 1;
2319
0
  b->yy_fill_buffer = 0;
2320
0
  b->yy_buffer_status = YY_BUFFER_NEW;
2321
2322
0
  yy_switch_to_buffer( b , yyscanner );
2323
2324
0
  return b;
2325
0
}
2326
2327
/** Setup the input buffer state to scan a string. The next call to yylex() will
2328
 * scan from a @e copy of @a str.
2329
 * @param yystr a NUL-terminated string to scan
2330
 * @param yyscanner The scanner object.
2331
 * @return the newly allocated buffer state object.
2332
 * @note If you want to scan bytes that may contain NUL values, then use
2333
 *       yy_scan_bytes() instead.
2334
 */
2335
YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
2336
0
{
2337
    
2338
0
  return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
2339
0
}
2340
2341
/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
2342
 * scan from a @e copy of @a bytes.
2343
 * @param yybytes the byte buffer to scan
2344
 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
2345
 * @param yyscanner The scanner object.
2346
 * @return the newly allocated buffer state object.
2347
 */
2348
YY_BUFFER_STATE yy_scan_bytes  (const char * yybytes, int  _yybytes_len , yyscan_t yyscanner)
2349
0
{
2350
0
  YY_BUFFER_STATE b;
2351
0
  char *buf;
2352
0
  yy_size_t n;
2353
0
  int i;
2354
    
2355
  /* Get memory for full buffer, including space for trailing EOB's. */
2356
0
  n = (yy_size_t) (_yybytes_len + 2);
2357
0
  buf = (char *) yyalloc( n , yyscanner );
2358
0
  if ( ! buf )
2359
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
2360
2361
0
  for ( i = 0; i < _yybytes_len; ++i )
2362
0
    buf[i] = yybytes[i];
2363
2364
0
  buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2365
2366
0
  b = yy_scan_buffer( buf, n , yyscanner);
2367
0
  if ( ! b )
2368
0
    YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
2369
2370
  /* It's okay to grow etc. this buffer, and we should throw it
2371
   * away when we're done.
2372
   */
2373
0
  b->yy_is_our_buffer = 1;
2374
2375
0
  return b;
2376
0
}
2377
2378
#ifndef YY_EXIT_FAILURE
2379
#define YY_EXIT_FAILURE 2
2380
#endif
2381
2382
static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
2383
0
{
2384
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2385
0
  (void)yyg;
2386
0
  fprintf( stderr, "%s\n", msg );
2387
0
  exit( YY_EXIT_FAILURE );
2388
0
}
2389
2390
/* Redefine yyless() so it works in section 3 code. */
2391
2392
#undef yyless
2393
#define yyless(n) \
2394
  do \
2395
    { \
2396
    /* Undo effects of setting up yytext. */ \
2397
        int yyless_macro_arg = (n); \
2398
        YY_LESS_LINENO(yyless_macro_arg);\
2399
    yytext[yyleng] = yyg->yy_hold_char; \
2400
    yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
2401
    yyg->yy_hold_char = *yyg->yy_c_buf_p; \
2402
    *yyg->yy_c_buf_p = '\0'; \
2403
    yyleng = yyless_macro_arg; \
2404
    } \
2405
  while ( 0 )
2406
2407
/* Accessor  methods (get/set functions) to struct members. */
2408
2409
/** Get the user-defined data for this scanner.
2410
 * @param yyscanner The scanner object.
2411
 */
2412
YY_EXTRA_TYPE yyget_extra  (yyscan_t yyscanner)
2413
0
{
2414
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2415
0
    return yyextra;
2416
0
}
2417
2418
/** Get the current line number.
2419
 * @param yyscanner The scanner object.
2420
 */
2421
int yyget_lineno  (yyscan_t yyscanner)
2422
0
{
2423
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2424
2425
0
        if (! YY_CURRENT_BUFFER)
2426
0
            return 0;
2427
    
2428
0
    return yylineno;
2429
0
}
2430
2431
/** Get the current column number.
2432
 * @param yyscanner The scanner object.
2433
 */
2434
int yyget_column  (yyscan_t yyscanner)
2435
0
{
2436
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2437
2438
0
        if (! YY_CURRENT_BUFFER)
2439
0
            return 0;
2440
    
2441
0
    return yycolumn;
2442
0
}
2443
2444
/** Get the input stream.
2445
 * @param yyscanner The scanner object.
2446
 */
2447
FILE *yyget_in  (yyscan_t yyscanner)
2448
0
{
2449
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2450
0
    return yyin;
2451
0
}
2452
2453
/** Get the output stream.
2454
 * @param yyscanner The scanner object.
2455
 */
2456
FILE *yyget_out  (yyscan_t yyscanner)
2457
0
{
2458
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2459
0
    return yyout;
2460
0
}
2461
2462
/** Get the length of the current token.
2463
 * @param yyscanner The scanner object.
2464
 */
2465
int yyget_leng  (yyscan_t yyscanner)
2466
0
{
2467
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2468
0
    return yyleng;
2469
0
}
2470
2471
/** Get the current token.
2472
 * @param yyscanner The scanner object.
2473
 */
2474
2475
char *yyget_text  (yyscan_t yyscanner)
2476
0
{
2477
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2478
0
    return yytext;
2479
0
}
2480
2481
/** Set the user-defined data. This data is never touched by the scanner.
2482
 * @param user_defined The data to be associated with this scanner.
2483
 * @param yyscanner The scanner object.
2484
 */
2485
void yyset_extra (YY_EXTRA_TYPE  user_defined , yyscan_t yyscanner)
2486
0
{
2487
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2488
0
    yyextra = user_defined ;
2489
0
}
2490
2491
/** Set the current line number.
2492
 * @param _line_number line number
2493
 * @param yyscanner The scanner object.
2494
 */
2495
void yyset_lineno (int  _line_number , yyscan_t yyscanner)
2496
0
{
2497
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2498
2499
        /* lineno is only valid if an input buffer exists. */
2500
0
        if (! YY_CURRENT_BUFFER )
2501
0
           YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
2502
    
2503
0
    yylineno = _line_number;
2504
0
}
2505
2506
/** Set the current column.
2507
 * @param _column_no column number
2508
 * @param yyscanner The scanner object.
2509
 */
2510
void yyset_column (int  _column_no , yyscan_t yyscanner)
2511
0
{
2512
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2513
2514
        /* column is only valid if an input buffer exists. */
2515
0
        if (! YY_CURRENT_BUFFER )
2516
0
           YY_FATAL_ERROR( "yyset_column called with no buffer" );
2517
    
2518
0
    yycolumn = _column_no;
2519
0
}
2520
2521
/** Set the input stream. This does not discard the current
2522
 * input buffer.
2523
 * @param _in_str A readable stream.
2524
 * @param yyscanner The scanner object.
2525
 * @see yy_switch_to_buffer
2526
 */
2527
void yyset_in (FILE *  _in_str , yyscan_t yyscanner)
2528
0
{
2529
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2530
0
    yyin = _in_str ;
2531
0
}
2532
2533
void yyset_out (FILE *  _out_str , yyscan_t yyscanner)
2534
0
{
2535
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2536
0
    yyout = _out_str ;
2537
0
}
2538
2539
int yyget_debug  (yyscan_t yyscanner)
2540
0
{
2541
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2542
0
    return yy_flex_debug;
2543
0
}
2544
2545
void yyset_debug (int  _bdebug , yyscan_t yyscanner)
2546
0
{
2547
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2548
0
    yy_flex_debug = _bdebug ;
2549
0
}
2550
2551
/* Accessor methods for yylval and yylloc */
2552
2553
YYSTYPE * yyget_lval  (yyscan_t yyscanner)
2554
0
{
2555
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2556
0
    return yylval;
2557
0
}
2558
2559
void yyset_lval (YYSTYPE *  yylval_param , yyscan_t yyscanner)
2560
0
{
2561
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2562
0
    yylval = yylval_param;
2563
0
}
2564
2565
/* User-visible API */
2566
2567
/* yylex_init is special because it creates the scanner itself, so it is
2568
 * the ONLY reentrant function that doesn't take the scanner as the last argument.
2569
 * That's why we explicitly handle the declaration, instead of using our macros.
2570
 */
2571
int yylex_init(yyscan_t* ptr_yy_globals)
2572
0
{
2573
0
    if (ptr_yy_globals == NULL){
2574
0
        errno = EINVAL;
2575
0
        return 1;
2576
0
    }
2577
2578
0
    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
2579
2580
0
    if (*ptr_yy_globals == NULL){
2581
0
        errno = ENOMEM;
2582
0
        return 1;
2583
0
    }
2584
2585
    /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
2586
0
    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2587
2588
0
    return yy_init_globals ( *ptr_yy_globals );
2589
0
}
2590
2591
/* yylex_init_extra has the same functionality as yylex_init, but follows the
2592
 * convention of taking the scanner as the last argument. Note however, that
2593
 * this is a *pointer* to a scanner, as it will be allocated by this call (and
2594
 * is the reason, too, why this function also must handle its own declaration).
2595
 * The user defined value in the first argument will be available to yyalloc in
2596
 * the yyextra field.
2597
 */
2598
int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals )
2599
0
{
2600
0
    struct yyguts_t dummy_yyguts;
2601
2602
0
    yyset_extra (yy_user_defined, &dummy_yyguts);
2603
2604
0
    if (ptr_yy_globals == NULL){
2605
0
        errno = EINVAL;
2606
0
        return 1;
2607
0
    }
2608
2609
0
    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
2610
2611
0
    if (*ptr_yy_globals == NULL){
2612
0
        errno = ENOMEM;
2613
0
        return 1;
2614
0
    }
2615
2616
    /* By setting to 0xAA, we expose bugs in
2617
    yy_init_globals. Leave at 0x00 for releases. */
2618
0
    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2619
2620
0
    yyset_extra (yy_user_defined, *ptr_yy_globals);
2621
2622
0
    return yy_init_globals ( *ptr_yy_globals );
2623
0
}
2624
2625
static int yy_init_globals (yyscan_t yyscanner)
2626
0
{
2627
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2628
    /* Initialization is the same as for the non-reentrant scanner.
2629
     * This function is called from yylex_destroy(), so don't allocate here.
2630
     */
2631
2632
0
    yyg->yy_buffer_stack = NULL;
2633
0
    yyg->yy_buffer_stack_top = 0;
2634
0
    yyg->yy_buffer_stack_max = 0;
2635
0
    yyg->yy_c_buf_p = NULL;
2636
0
    yyg->yy_init = 0;
2637
0
    yyg->yy_start = 0;
2638
2639
0
    yyg->yy_start_stack_ptr = 0;
2640
0
    yyg->yy_start_stack_depth = 0;
2641
0
    yyg->yy_start_stack =  NULL;
2642
2643
/* Defined in main.c */
2644
#ifdef YY_STDINIT
2645
    yyin = stdin;
2646
    yyout = stdout;
2647
#else
2648
0
    yyin = NULL;
2649
0
    yyout = NULL;
2650
0
#endif
2651
2652
    /* For future reference: Set errno on error, since we are called by
2653
     * yylex_init()
2654
     */
2655
0
    return 0;
2656
0
}
2657
2658
/* yylex_destroy is for both reentrant and non-reentrant scanners. */
2659
int yylex_destroy  (yyscan_t yyscanner)
2660
0
{
2661
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2662
2663
    /* Pop the buffer stack, destroying each element. */
2664
0
  while(YY_CURRENT_BUFFER){
2665
0
    yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
2666
0
    YY_CURRENT_BUFFER_LVALUE = NULL;
2667
0
    yypop_buffer_state(yyscanner);
2668
0
  }
2669
2670
  /* Destroy the stack itself. */
2671
0
  yyfree(yyg->yy_buffer_stack , yyscanner);
2672
0
  yyg->yy_buffer_stack = NULL;
2673
2674
    /* Destroy the start condition stack. */
2675
0
        yyfree( yyg->yy_start_stack , yyscanner );
2676
0
        yyg->yy_start_stack = NULL;
2677
2678
    /* Reset the globals. This is important in a non-reentrant scanner so the next time
2679
     * yylex() is called, initialization will occur. */
2680
0
    yy_init_globals( yyscanner);
2681
2682
    /* Destroy the main struct (reentrant only). */
2683
0
    yyfree ( yyscanner , yyscanner );
2684
0
    yyscanner = NULL;
2685
0
    return 0;
2686
0
}
2687
2688
/*
2689
 * Internal utility routines.
2690
 */
2691
2692
#ifndef yytext_ptr
2693
static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
2694
{
2695
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2696
  (void)yyg;
2697
2698
  int i;
2699
  for ( i = 0; i < n; ++i )
2700
    s1[i] = s2[i];
2701
}
2702
#endif
2703
2704
#ifdef YY_NEED_STRLEN
2705
static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
2706
{
2707
  int n;
2708
  for ( n = 0; s[n]; ++n )
2709
    ;
2710
2711
  return n;
2712
}
2713
#endif
2714
2715
void *yyalloc (yy_size_t  size , yyscan_t yyscanner)
2716
0
{
2717
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2718
0
  (void)yyg;
2719
0
  return malloc(size);
2720
0
}
2721
2722
void *yyrealloc  (void * ptr, yy_size_t  size , yyscan_t yyscanner)
2723
0
{
2724
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2725
0
  (void)yyg;
2726
2727
  /* The cast to (char *) in the following accommodates both
2728
   * implementations that use char* generic pointers, and those
2729
   * that use void* generic pointers.  It works with the latter
2730
   * because both ANSI C and C++ allow castless assignment from
2731
   * any pointer type to void*, and deal with argument conversions
2732
   * as though doing an assignment.
2733
   */
2734
0
  return realloc(ptr, size);
2735
0
}
2736
2737
void yyfree (void * ptr , yyscan_t yyscanner)
2738
0
{
2739
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2740
0
  (void)yyg;
2741
0
  free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
2742
0
}
2743
2744
#define YYTABLES_NAME "yytables"
2745
2746
#line 499 "libyara/re_lexer.l"
2747
2748
2749
int escaped_char_value(
2750
    char* text,
2751
    uint8_t* value,
2752
    bool strict_escape)
2753
0
{
2754
0
  unsigned int hex_value;
2755
0
  char hex[3];
2756
2757
0
  assert(text[0] == '\\');
2758
2759
0
  switch(text[1])
2760
0
  {
2761
0
  case 'x':
2762
0
    if (!isxdigit(text[2]) || !isxdigit(text[3]))
2763
0
      return 0;
2764
0
    hex[0] = text[2];
2765
0
    hex[1] = text[3];
2766
0
    hex[2] = '\0';
2767
0
    sscanf(hex, "%x", &hex_value);
2768
0
    *value = (uint8_t) hex_value;
2769
0
    break;
2770
2771
0
  case 'n':
2772
0
    *value = '\n';
2773
0
    break;
2774
2775
0
  case 't':
2776
0
    *value = '\t';
2777
0
    break;
2778
2779
0
  case 'r':
2780
0
    *value = '\r';
2781
0
    break;
2782
2783
0
  case 'f':
2784
0
    *value = '\f';
2785
0
    break;
2786
2787
0
  case 'a':
2788
0
    *value = '\a';
2789
0
    break;
2790
2791
  // Support metacharacters in escape sequences
2792
0
  case '\\':
2793
0
  case '^':
2794
0
  case '$':
2795
0
  case '.':
2796
0
  case '|':
2797
0
  case '(':
2798
0
  case ')':
2799
0
  case '[':
2800
0
  case ']':
2801
2802
  // Support other special characters that are used in rules and need to be escaped
2803
0
  case '*':
2804
0
  case '+':
2805
0
  case '?':
2806
0
  case '"':
2807
0
  case '\'':
2808
0
  case '-':
2809
0
  case '{':
2810
0
  case '}':
2811
0
  case '#':
2812
0
  case ':':
2813
0
  case '_':
2814
0
  case '=':
2815
0
  case '/':
2816
0
  case '!':
2817
0
  case ',':
2818
0
  case '@':
2819
0
  case '<':
2820
0
  case '>':
2821
0
  case '~':
2822
0
  case '&':
2823
0
  case '%':
2824
0
    *value = text[1];
2825
0
    break;
2826
0
  default:
2827
0
    *value = text[1];
2828
0
    if (strict_escape)
2829
0
      return UNKNOWN_ESCAPE_SEQUENCE;
2830
0
    return VALID_ESCAPE_SEQUENCE;
2831
0
  }
2832
2833
0
  return VALID_ESCAPE_SEQUENCE;
2834
0
}
2835
2836
2837
#ifdef __cplusplus
2838
#define RE_YY_INPUT yyinput
2839
#else
2840
0
#define RE_YY_INPUT input
2841
#endif
2842
2843
2844
int read_escaped_char(
2845
    yyscan_t yyscanner,
2846
    uint8_t* escaped_char,
2847
    bool strict_escape)
2848
0
{
2849
0
  char text[4] = {0, 0, 0, 0};
2850
2851
0
  text[0] = '\\';
2852
0
  text[1] = RE_YY_INPUT(yyscanner);
2853
2854
0
  if (text[1] == EOF || text[1] == 0)
2855
0
    return 0;
2856
2857
0
  if (text[1] == 'x')
2858
0
  {
2859
0
    text[2] = RE_YY_INPUT(yyscanner);
2860
2861
0
    if (text[2] == EOF || text[2] == 0)
2862
0
      return 0;
2863
2864
0
    text[3] = RE_YY_INPUT(yyscanner);
2865
2866
0
    if (text[3] == EOF || text[3] == 0)
2867
0
      return 0;
2868
0
  }
2869
2870
0
  return escaped_char_value(text, escaped_char, strict_escape);
2871
0
}
2872
2873
2874
//
2875
// yyfatal (actually named re_yyfatal because of the '%option prefix="re_yy"'
2876
// directive) is called when a fatal error occurs in the parser. When this
2877
// happens we are deep inside the parsing logic generated by flex/bison and
2878
// the only way to exit gracefully from there is using setjmp/longjmp.
2879
//
2880
void yyfatal(
2881
    yyscan_t yyscanner,
2882
    const char *error_message)
2883
0
{
2884
0
  jmp_buf* recovery_trampoline = (jmp_buf*) yr_thread_storage_get_value(
2885
0
      &yr_yyfatal_trampoline_tls);
2886
2887
0
  longjmp(*recovery_trampoline, 1);
2888
0
}
2889
2890
2891
void yyerror(
2892
    yyscan_t yyscanner,
2893
    RE_LEX_ENVIRONMENT* lex_env,
2894
    const char *error_message)
2895
0
{
2896
  // if lex_env->last_error was set to some error code before
2897
  // don't overwrite it, we are interested in the first error, not in
2898
  // subsequent errors like "syntax error, unexpected $end" caused by
2899
  // early parser termination.
2900
2901
0
  if (lex_env->last_error == ERROR_SUCCESS || lex_env->last_error == ERROR_UNKNOWN_ESCAPE_SEQUENCE)
2902
0
  {
2903
0
    lex_env->last_error = ERROR_INVALID_REGULAR_EXPRESSION;
2904
2905
0
    strlcpy(
2906
0
        lex_env->last_error_message,
2907
0
        error_message,
2908
0
        sizeof(lex_env->last_error_message));
2909
0
  }
2910
0
}
2911
2912
void yywarning(
2913
    yyscan_t yyscanner,
2914
    RE_LEX_ENVIRONMENT* lex_env,
2915
    const char *error_message)
2916
0
{
2917
  // Do not overwrite Errors
2918
  // print out warning only if there is not any other error beforehand
2919
2920
0
  if (lex_env->last_error == ERROR_SUCCESS)
2921
0
  {
2922
0
    lex_env->last_error = ERROR_UNKNOWN_ESCAPE_SEQUENCE;
2923
2924
0
    strlcpy(
2925
0
        lex_env->last_error_message,
2926
0
        error_message,
2927
0
        sizeof(lex_env->last_error_message));
2928
0
  }
2929
0
}
2930
2931
int yr_parse_re_string(
2932
  const char* re_string,
2933
  RE_AST** re_ast,
2934
  RE_ERROR* error,
2935
  int flags)
2936
0
{
2937
0
  yyscan_t yyscanner;
2938
0
  jmp_buf recovery_trampoline;
2939
0
  RE_LEX_ENVIRONMENT lex_env;
2940
2941
0
  lex_env.last_error = ERROR_SUCCESS;
2942
0
  if (flags & RE_PARSER_FLAG_ENABLE_STRICT_ESCAPE_SEQUENCES)
2943
0
    lex_env.strict_escape = true;
2944
0
   else
2945
0
    lex_env.strict_escape = false;
2946
0
  lex_env.last_error_message[0] = '\0';
2947
2948
0
  yr_thread_storage_set_value(
2949
0
      &yr_yyfatal_trampoline_tls,
2950
0
      &recovery_trampoline);
2951
2952
  // setjmp returns a non-zero value only when we are returning to this
2953
  // point via a call to longjmp to the recovery trampoline.
2954
0
  if (setjmp(recovery_trampoline) != 0)
2955
0
    return ERROR_INTERNAL_FATAL_ERROR;
2956
2957
0
  FAIL_ON_ERROR(yr_re_ast_create(re_ast));
2958
2959
0
  if (yylex_init(&yyscanner) != 0)
2960
0
  {
2961
0
    yr_re_ast_destroy(*re_ast);
2962
0
    *re_ast = NULL;
2963
0
    return ERROR_INSUFFICIENT_MEMORY;
2964
0
  }
2965
2966
0
  yyset_extra(*re_ast, yyscanner);
2967
0
  yy_scan_string(re_string, yyscanner);
2968
2969
0
  yyparse(yyscanner, &lex_env);
2970
0
  yylex_destroy(yyscanner);
2971
2972
0
  if (lex_env.last_error != ERROR_SUCCESS)
2973
0
  {
2974
0
    if (lex_env.last_error != ERROR_UNKNOWN_ESCAPE_SEQUENCE)
2975
0
    {
2976
0
      yr_re_ast_destroy(*re_ast);
2977
0
      *re_ast = NULL;
2978
0
    }
2979
2980
0
    strlcpy(
2981
0
        error->message,
2982
0
        lex_env.last_error_message,
2983
0
        sizeof(error->message));
2984
2985
0
    return lex_env.last_error;
2986
0
  }
2987
2988
0
  return ERROR_SUCCESS;
2989
0
}
2990