Coverage Report

Created: 2025-07-11 06:07

/src/yara/libyara/re_lexer.c
Line
Count
Source (jump to first uncovered line)
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
#endif
774
775
// Bitmap with 1 bit for each of the 256 characters in the ASCII table. The bit
776
// is set to 1 if the corresponding character is alphanumeric or 0 if otherwise.
777
static uint8_t word_chars[] = {
778
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03,
779
    0xFE, 0xFF, 0xFF, 0x87, 0xFE, 0xFF, 0xFF, 0x07,
780
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
781
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
782
783
// Bitmap with 1 bit for each of the 256 characters in the ASCII table. The bit
784
// is set to 1 if the corresponding character is considered a space. Space
785
// characters include horizontal and vertical tabs, carriage return, new line
786
// and form feed (\t, \v, \r, \n, \f).
787
static uint8_t space_chars[] = {
788
    0x00, 0x3E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
789
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
790
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
791
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
792
793
int escaped_char_value(
794
    char* text,
795
    uint8_t* value,
796
    bool strict_escape);
797
798
int read_escaped_char(
799
    yyscan_t yyscanner,
800
    uint8_t* escaped_char,
801
    bool strict_escape);
802
803
#line 803 "libyara/re_lexer.c"
804
#define YY_NO_UNISTD_H 1
805
806
#line 806 "libyara/re_lexer.c"
807
808
0
#define INITIAL 0
809
0
#define char_class 1
810
811
#ifndef YY_NO_UNISTD_H
812
/* Special case for "unistd.h", since it is non-ANSI. We include it way
813
 * down here because we want the user's section 1 to have been scanned first.
814
 * The user has a chance to override it with an option.
815
 */
816
#include <unistd.h>
817
#endif
818
819
#ifndef YY_EXTRA_TYPE
820
#define YY_EXTRA_TYPE void *
821
#endif
822
823
/* Holds the entire state of the reentrant scanner. */
824
struct yyguts_t
825
    {
826
827
    /* User-defined. Not touched by flex. */
828
    YY_EXTRA_TYPE yyextra_r;
829
830
    /* The rest are the same as the globals declared in the non-reentrant scanner. */
831
    FILE *yyin_r, *yyout_r;
832
    size_t yy_buffer_stack_top; /**< index of top of stack. */
833
    size_t yy_buffer_stack_max; /**< capacity of stack. */
834
    YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
835
    char yy_hold_char;
836
    int yy_n_chars;
837
    int yyleng_r;
838
    char *yy_c_buf_p;
839
    int yy_init;
840
    int yy_start;
841
    int yy_did_buffer_switch_on_eof;
842
    int yy_start_stack_ptr;
843
    int yy_start_stack_depth;
844
    int *yy_start_stack;
845
    yy_state_type yy_last_accepting_state;
846
    char* yy_last_accepting_cpos;
847
848
    int yylineno_r;
849
    int yy_flex_debug_r;
850
851
    char *yytext_r;
852
    int yy_more_flag;
853
    int yy_more_len;
854
855
    YYSTYPE * yylval_r;
856
857
    }; /* end struct yyguts_t */
858
859
static int yy_init_globals ( yyscan_t yyscanner );
860
861
    /* This must go here because YYSTYPE and YYLTYPE are included
862
     * from bison output in section 1.*/
863
0
    #    define yylval yyg->yylval_r
864
    
865
int yylex_init (yyscan_t* scanner);
866
867
int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner);
868
869
/* Accessor methods to globals.
870
   These are made visible to non-reentrant scanners for convenience. */
871
872
int yylex_destroy ( yyscan_t yyscanner );
873
874
int yyget_debug ( yyscan_t yyscanner );
875
876
void yyset_debug ( int debug_flag , yyscan_t yyscanner );
877
878
YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
879
880
void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
881
882
FILE *yyget_in ( yyscan_t yyscanner );
883
884
void yyset_in  ( FILE * _in_str , yyscan_t yyscanner );
885
886
FILE *yyget_out ( yyscan_t yyscanner );
887
888
void yyset_out  ( FILE * _out_str , yyscan_t yyscanner );
889
890
      int yyget_leng ( yyscan_t yyscanner );
891
892
char *yyget_text ( yyscan_t yyscanner );
893
894
int yyget_lineno ( yyscan_t yyscanner );
895
896
void yyset_lineno ( int _line_number , yyscan_t yyscanner );
897
898
int yyget_column  ( yyscan_t yyscanner );
899
900
void yyset_column ( int _column_no , yyscan_t yyscanner );
901
902
YYSTYPE * yyget_lval ( yyscan_t yyscanner );
903
904
void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner );
905
906
/* Macros after this point can all be overridden by user definitions in
907
 * section 1.
908
 */
909
910
#ifndef YY_SKIP_YYWRAP
911
#ifdef __cplusplus
912
extern "C" int yywrap ( yyscan_t yyscanner );
913
#else
914
extern int yywrap ( yyscan_t yyscanner );
915
#endif
916
#endif
917
918
#ifndef YY_NO_UNPUT
919
    
920
#endif
921
922
#ifndef yytext_ptr
923
static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
924
#endif
925
926
#ifdef YY_NEED_STRLEN
927
static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
928
#endif
929
930
#ifndef YY_NO_INPUT
931
#ifdef __cplusplus
932
static int yyinput ( yyscan_t yyscanner );
933
#else
934
static int input ( yyscan_t yyscanner );
935
#endif
936
937
#endif
938
939
/* Amount of stuff to slurp up with each read. */
940
#ifndef YY_READ_BUF_SIZE
941
#ifdef __ia64__
942
/* On IA-64, the buffer size is 16k, not 8k */
943
#define YY_READ_BUF_SIZE 16384
944
#else
945
0
#define YY_READ_BUF_SIZE 8192
946
#endif /* __ia64__ */
947
#endif
948
949
/* Copy whatever the last rule matched to the standard output. */
950
#ifndef ECHO
951
/* This used to be an fputs(), but since the string might contain NUL's,
952
 * we now use fwrite().
953
 */
954
#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
955
#endif
956
957
/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
958
 * is returned in "result".
959
 */
960
#ifndef YY_INPUT
961
#define YY_INPUT(buf,result,max_size) \
962
0
  if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
963
0
    { \
964
0
    int c = '*'; \
965
0
    int n; \
966
0
    for ( n = 0; n < max_size && \
967
0
           (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
968
0
      buf[n] = (char) c; \
969
0
    if ( c == '\n' ) \
970
0
      buf[n++] = (char) c; \
971
0
    if ( c == EOF && ferror( yyin ) ) \
972
0
      YY_FATAL_ERROR( "input in flex scanner failed" ); \
973
0
    result = n; \
974
0
    } \
975
0
  else \
976
0
    { \
977
0
    errno=0; \
978
0
    while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
979
0
      { \
980
0
      if( errno != EINTR) \
981
0
        { \
982
0
        YY_FATAL_ERROR( "input in flex scanner failed" ); \
983
0
        break; \
984
0
        } \
985
0
      errno=0; \
986
0
      clearerr(yyin); \
987
0
      } \
988
0
    }\
989
\
990
991
#endif
992
993
/* No semi-colon after return; correct usage is to write "yyterminate();" -
994
 * we don't want an extra ';' after the "return" because that will cause
995
 * some compilers to complain about unreachable statements.
996
 */
997
#ifndef yyterminate
998
0
#define yyterminate() return YY_NULL
999
#endif
1000
1001
/* Number of entries by which start-condition stack grows. */
1002
#ifndef YY_START_STACK_INCR
1003
#define YY_START_STACK_INCR 25
1004
#endif
1005
1006
/* Report a fatal error. */
1007
#ifndef YY_FATAL_ERROR
1008
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
1009
#endif
1010
1011
/* end tables serialization structures and prototypes */
1012
1013
/* Default declaration of generated scanner - a define so the user can
1014
 * easily add parameters.
1015
 */
1016
#ifndef YY_DECL
1017
#define YY_DECL_IS_OURS 1
1018
1019
extern int yylex \
1020
               (YYSTYPE * yylval_param , yyscan_t yyscanner);
1021
1022
#define YY_DECL int yylex \
1023
               (YYSTYPE * yylval_param , yyscan_t yyscanner)
1024
#endif /* !YY_DECL */
1025
1026
/* Code executed at the beginning of each rule, after yytext and yyleng
1027
 * have been set up.
1028
 */
1029
#ifndef YY_USER_ACTION
1030
#define YY_USER_ACTION
1031
#endif
1032
1033
/* Code executed at the end of each rule. */
1034
#ifndef YY_BREAK
1035
0
#define YY_BREAK /*LINTED*/break;
1036
#endif
1037
1038
#define YY_RULE_SETUP \
1039
  YY_USER_ACTION
1040
1041
/** The main scanner function which does all the work.
1042
 */
1043
YY_DECL
1044
0
{
1045
0
  yy_state_type yy_current_state;
1046
0
  char *yy_cp, *yy_bp;
1047
0
  int yy_act;
1048
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1049
1050
0
    yylval = yylval_param;
1051
1052
0
  if ( !yyg->yy_init )
1053
0
    {
1054
0
    yyg->yy_init = 1;
1055
1056
#ifdef YY_USER_INIT
1057
    YY_USER_INIT;
1058
#endif
1059
1060
0
    if ( ! yyg->yy_start )
1061
0
      yyg->yy_start = 1; /* first start state */
1062
1063
0
    if ( ! yyin )
1064
0
      yyin = stdin;
1065
1066
0
    if ( ! yyout )
1067
0
      yyout = stdout;
1068
1069
0
    if ( ! YY_CURRENT_BUFFER ) {
1070
0
      yyensure_buffer_stack (yyscanner);
1071
0
      YY_CURRENT_BUFFER_LVALUE =
1072
0
        yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
1073
0
    }
1074
1075
0
    yy_load_buffer_state( yyscanner );
1076
0
    }
1077
1078
0
  {
1079
0
#line 114 "libyara/re_lexer.l"
1080
1081
1082
0
#line 1082 "libyara/re_lexer.c"
1083
1084
0
  while ( /*CONSTCOND*/1 )    /* loops until end-of-file is reached */
1085
0
    {
1086
0
    yy_cp = yyg->yy_c_buf_p;
1087
1088
    /* Support of yytext. */
1089
0
    *yy_cp = yyg->yy_hold_char;
1090
1091
    /* yy_bp points to the position in yy_ch_buf of the start of
1092
     * the current run.
1093
     */
1094
0
    yy_bp = yy_cp;
1095
1096
0
    yy_current_state = yyg->yy_start;
1097
0
yy_match:
1098
0
    do
1099
0
      {
1100
0
      YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
1101
0
      if ( yy_accept[yy_current_state] )
1102
0
        {
1103
0
        yyg->yy_last_accepting_state = yy_current_state;
1104
0
        yyg->yy_last_accepting_cpos = yy_cp;
1105
0
        }
1106
0
      while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1107
0
        {
1108
0
        yy_current_state = (int) yy_def[yy_current_state];
1109
0
        if ( yy_current_state >= 47 )
1110
0
          yy_c = yy_meta[yy_c];
1111
0
        }
1112
0
      yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1113
0
      ++yy_cp;
1114
0
      }
1115
0
    while ( yy_current_state != 46 );
1116
0
    yy_cp = yyg->yy_last_accepting_cpos;
1117
0
    yy_current_state = yyg->yy_last_accepting_state;
1118
1119
0
yy_find_action:
1120
0
    yy_act = yy_accept[yy_current_state];
1121
1122
0
    YY_DO_BEFORE_ACTION;
1123
1124
0
    if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
1125
0
      {
1126
0
      int yyl;
1127
0
      for ( yyl = 0; yyl < yyleng; ++yyl )
1128
0
        if ( yytext[yyl] == '\n' )
1129
          
1130
0
    do{ yylineno++;
1131
0
        yycolumn=0;
1132
0
    }while(0)
1133
0
;
1134
0
      }
1135
1136
0
do_action:  /* This label is used only to access EOF actions. */
1137
1138
0
    switch ( yy_act )
1139
0
  { /* beginning of action switch */
1140
0
      case 0: /* must back up */
1141
      /* undo the effects of YY_DO_BEFORE_ACTION */
1142
0
      *yy_cp = yyg->yy_hold_char;
1143
0
      yy_cp = yyg->yy_last_accepting_cpos;
1144
0
      yy_current_state = yyg->yy_last_accepting_state;
1145
0
      goto yy_find_action;
1146
1147
0
case 1:
1148
0
YY_RULE_SETUP
1149
0
#line 116 "libyara/re_lexer.l"
1150
0
{
1151
1152
  // Examples: {3,8} {3, 8}, {3 ,8} {3 , 8} {0,5} {,5} {7,}
1153
1154
0
  int hi_bound;
1155
0
  int lo_bound = atoi(yytext + 1);
1156
1157
0
  char* comma = strchr(yytext, ',');
1158
0
  char* hi_bound_ptr = comma + 1;
1159
1160
  // Skip spaces after the comma, if any.
1161
0
  while (*hi_bound_ptr == ' ') hi_bound_ptr++;
1162
1163
0
  if (*hi_bound_ptr == '}')
1164
0
    hi_bound = RE_MAX_RANGE;
1165
0
  else
1166
0
    hi_bound = atoi(hi_bound_ptr);
1167
1168
0
  if (hi_bound > RE_MAX_RANGE)
1169
0
  {
1170
0
    yyerror(yyscanner, lex_env, "repeat interval too large");
1171
0
    yyterminate();
1172
0
  }
1173
1174
0
  if (hi_bound < lo_bound || hi_bound < 0 || lo_bound < 0)
1175
0
  {
1176
0
    yyerror(yyscanner, lex_env, "bad repeat interval");
1177
0
    yyterminate();
1178
0
  }
1179
1180
0
  yylval->range = (hi_bound << 16) | lo_bound;
1181
1182
0
  return _RANGE_;
1183
0
}
1184
0
  YY_BREAK
1185
0
case 2:
1186
0
YY_RULE_SETUP
1187
0
#line 152 "libyara/re_lexer.l"
1188
0
{
1189
1190
  // Example: {10}
1191
1192
0
  int value = atoi(yytext + 1);
1193
1194
  // atoi can return a negative value if the input string represents a number
1195
  // too large to fit in an integer.
1196
1197
0
  if (value > RE_MAX_RANGE || value < 0)
1198
0
  {
1199
0
    yyerror(yyscanner, lex_env, "repeat interval too large");
1200
0
    yyterminate();
1201
0
  }
1202
1203
0
  yylval->range = (value << 16) | value;
1204
1205
0
  return _RANGE_;
1206
0
}
1207
0
  YY_BREAK
1208
0
case 3:
1209
0
YY_RULE_SETUP
1210
0
#line 173 "libyara/re_lexer.l"
1211
0
{
1212
1213
  // Start of a negated character class. Example: [^abcd]
1214
1215
0
  BEGIN(char_class);
1216
0
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1217
0
  LEX_ENV->re_class.negated = true;
1218
0
}
1219
0
  YY_BREAK
1220
0
case 4:
1221
0
YY_RULE_SETUP
1222
0
#line 182 "libyara/re_lexer.l"
1223
0
{
1224
1225
  // Start of character negated class containing a ].
1226
  // Example: [^]abc] this must be interpreted as a class
1227
  // not matching ], a, b, nor c
1228
1229
0
  BEGIN(char_class);
1230
0
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1231
0
  LEX_ENV->re_class.negated = true;
1232
0
  LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8;
1233
0
}
1234
0
  YY_BREAK
1235
0
case 5:
1236
0
YY_RULE_SETUP
1237
0
#line 195 "libyara/re_lexer.l"
1238
0
{
1239
1240
  // Start of character class containing a ].
1241
  // Example: []abc] this must be interpreted as a class
1242
  // matching ], a, b, or c.
1243
1244
0
  BEGIN(char_class);
1245
0
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1246
0
  LEX_ENV->re_class.negated = false;
1247
0
  LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8;
1248
0
}
1249
0
  YY_BREAK
1250
0
case 6:
1251
0
YY_RULE_SETUP
1252
0
#line 208 "libyara/re_lexer.l"
1253
0
{
1254
1255
  // Start of character class. Example: [abcd]
1256
1257
0
  BEGIN(char_class);
1258
0
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1259
0
  LEX_ENV->re_class.negated = false;
1260
0
}
1261
0
  YY_BREAK
1262
0
case 7:
1263
/* rule 7 can match eol */
1264
0
YY_RULE_SETUP
1265
0
#line 218 "libyara/re_lexer.l"
1266
0
{
1267
1268
  // Any non-special character is passed as a CHAR token to the scanner.
1269
1270
0
  yylval->integer = yytext[0];
1271
0
  return _CHAR_;
1272
0
}
1273
0
  YY_BREAK
1274
0
case 8:
1275
0
YY_RULE_SETUP
1276
0
#line 227 "libyara/re_lexer.l"
1277
0
{
1278
0
  return _WORD_CHAR_;
1279
0
}
1280
0
  YY_BREAK
1281
0
case 9:
1282
0
YY_RULE_SETUP
1283
0
#line 232 "libyara/re_lexer.l"
1284
0
{
1285
0
  return _NON_WORD_CHAR_;
1286
0
}
1287
0
  YY_BREAK
1288
0
case 10:
1289
0
YY_RULE_SETUP
1290
0
#line 237 "libyara/re_lexer.l"
1291
0
{
1292
0
  return _SPACE_;
1293
0
}
1294
0
  YY_BREAK
1295
0
case 11:
1296
0
YY_RULE_SETUP
1297
0
#line 242 "libyara/re_lexer.l"
1298
0
{
1299
0
  return _NON_SPACE_;
1300
0
}
1301
0
  YY_BREAK
1302
0
case 12:
1303
0
YY_RULE_SETUP
1304
0
#line 247 "libyara/re_lexer.l"
1305
0
{
1306
0
  return _DIGIT_;
1307
0
}
1308
0
  YY_BREAK
1309
0
case 13:
1310
0
YY_RULE_SETUP
1311
0
#line 252 "libyara/re_lexer.l"
1312
0
{
1313
0
  return _NON_DIGIT_;
1314
0
}
1315
0
  YY_BREAK
1316
0
case 14:
1317
0
YY_RULE_SETUP
1318
0
#line 257 "libyara/re_lexer.l"
1319
0
{
1320
0
  return _WORD_BOUNDARY_;
1321
0
}
1322
0
  YY_BREAK
1323
0
case 15:
1324
0
YY_RULE_SETUP
1325
0
#line 261 "libyara/re_lexer.l"
1326
0
{
1327
0
  return _NON_WORD_BOUNDARY_;
1328
0
}
1329
0
  YY_BREAK
1330
0
case 16:
1331
0
YY_RULE_SETUP
1332
0
#line 266 "libyara/re_lexer.l"
1333
0
{
1334
1335
0
  yyerror(yyscanner, lex_env, "backreferences are not allowed");
1336
0
  yyterminate();
1337
0
}
1338
0
  YY_BREAK
1339
0
case 17:
1340
0
YY_RULE_SETUP
1341
0
#line 273 "libyara/re_lexer.l"
1342
0
{
1343
1344
0
  uint8_t c;
1345
0
  int return_code;
1346
1347
0
  return_code = read_escaped_char(yyscanner, &c, LEX_ENV->strict_escape);
1348
0
  if (return_code == VALID_ESCAPE_SEQUENCE)
1349
0
  {
1350
0
    yylval->integer = c;
1351
0
    return _CHAR_;
1352
0
  }
1353
0
  else if (return_code == UNKNOWN_ESCAPE_SEQUENCE)
1354
0
  {
1355
0
    yywarning(yyscanner, lex_env, "unknown escape sequence");
1356
0
    yylval->integer = c;
1357
0
    return _CHAR_;
1358
0
  }
1359
0
  else
1360
0
  {
1361
0
    yyerror(yyscanner, lex_env, "illegal escape sequence");
1362
0
    yyterminate();
1363
0
  }
1364
0
}
1365
0
  YY_BREAK
1366
0
case 18:
1367
0
YY_RULE_SETUP
1368
0
#line 298 "libyara/re_lexer.l"
1369
0
{
1370
1371
  // End of character class.
1372
0
  yylval->re_class = (RE_CLASS*) yr_malloc(sizeof(RE_CLASS));
1373
0
  memcpy(yylval->re_class->bitmap, LEX_ENV->re_class.bitmap, 32);
1374
1375
0
  yylval->re_class->negated = LEX_ENV->re_class.negated;
1376
1377
0
  BEGIN(INITIAL);
1378
0
  return _CLASS_;
1379
0
}
1380
0
  YY_BREAK
1381
0
case 19:
1382
/* rule 19 can match eol */
1383
0
YY_RULE_SETUP
1384
0
#line 312 "libyara/re_lexer.l"
1385
0
{
1386
1387
  // A range inside a character class. The regexp is...
1388
  //
1389
  //   ( \x{hex_digit}{2}    Hex digit (i.e: \x01) ...
1390
  //   | \.                  ...or any escaped character (i.e. \\, \-) ...
1391
  //   | [^]\]               ...or any character except ] and \ ...
1392
  //   )
1393
  //   -                     ... followed by -
1394
  //   [^]]                  ... followed by any character except ]
1395
  //
1396
  // Some examples:
1397
  //
1398
  //  [abc0-9]
1399
  //      ^-^ matching range 0-9
1400
  //
1401
  //  [a-za-]
1402
  //   ^-^- matching range a-z
1403
  //
1404
  //  [\.-a]
1405
  //   ^--^- matching range \.-a
1406
  //
1407
1408
0
  uint16_t c;
1409
0
  uint8_t start = yytext[0];
1410
0
  uint8_t end = yytext[2];
1411
1412
0
  if (start == '\\')
1413
0
  {
1414
0
    if (!escaped_char_value(yytext, &start, LEX_ENV->strict_escape))
1415
0
    {
1416
0
      yyerror(yyscanner, lex_env, "illegal escape sequence");
1417
0
      yyterminate();
1418
0
    }
1419
1420
0
    if (yytext[1] == 'x')
1421
0
      end = yytext[5];
1422
0
    else
1423
0
      end = yytext[3];
1424
0
  }
1425
1426
0
  if (end == '\\')
1427
0
  {
1428
0
    if (!read_escaped_char(yyscanner, &end, LEX_ENV->strict_escape))
1429
0
    {
1430
0
      yyerror(yyscanner, lex_env, "illegal escape sequence");
1431
0
      yyterminate();
1432
0
    }
1433
0
  }
1434
1435
0
  if (end < start)
1436
0
  {
1437
0
    yyerror(yyscanner, lex_env, "bad character range");
1438
0
    yyterminate();
1439
0
  }
1440
1441
0
  for (c = start; c <= end; c++)
1442
0
  {
1443
0
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1444
0
  }
1445
0
}
1446
0
  YY_BREAK
1447
0
case 20:
1448
0
YY_RULE_SETUP
1449
0
#line 375 "libyara/re_lexer.l"
1450
0
{
1451
1452
0
  for (int i = 0; i < 32; i++)
1453
0
    LEX_ENV->re_class.bitmap[i] |= word_chars[i];
1454
0
}
1455
0
  YY_BREAK
1456
0
case 21:
1457
0
YY_RULE_SETUP
1458
0
#line 382 "libyara/re_lexer.l"
1459
0
{
1460
1461
0
  for (int i = 0; i < 32; i++)
1462
0
    LEX_ENV->re_class.bitmap[i] |= ~word_chars[i];
1463
0
}
1464
0
  YY_BREAK
1465
0
case 22:
1466
0
YY_RULE_SETUP
1467
0
#line 389 "libyara/re_lexer.l"
1468
0
{
1469
1470
0
  for (int i = 0; i < 32; i++)
1471
0
    LEX_ENV->re_class.bitmap[i] |= space_chars[i];
1472
0
}
1473
0
  YY_BREAK
1474
0
case 23:
1475
0
YY_RULE_SETUP
1476
0
#line 396 "libyara/re_lexer.l"
1477
0
{
1478
1479
0
  for (int i = 0; i < 32; i++)
1480
0
    LEX_ENV->re_class.bitmap[i] |= ~space_chars[i];
1481
0
}
1482
0
  YY_BREAK
1483
0
case 24:
1484
0
YY_RULE_SETUP
1485
0
#line 403 "libyara/re_lexer.l"
1486
0
{
1487
1488
0
  for (char c = '0'; c <= '9'; c++)
1489
0
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1490
0
}
1491
0
  YY_BREAK
1492
0
case 25:
1493
0
YY_RULE_SETUP
1494
0
#line 410 "libyara/re_lexer.l"
1495
0
{
1496
1497
0
  for (int i = 0; i < 32; i++)
1498
0
  {
1499
    // digits 0-7 are in the sixth byte of the vector, let that byte alone
1500
0
    if (i == 6)
1501
0
      continue;
1502
1503
    // digits 8 and 9 are the lowest two bits in the seventh byte of the
1504
    // vector, let those bits alone.
1505
0
    if (i == 7)
1506
0
      LEX_ENV->re_class.bitmap[i] |= 0xFC;
1507
0
    else
1508
0
      LEX_ENV->re_class.bitmap[i] = 0xFF;
1509
0
  }
1510
0
}
1511
0
  YY_BREAK
1512
0
case 26:
1513
0
YY_RULE_SETUP
1514
0
#line 428 "libyara/re_lexer.l"
1515
0
{
1516
1517
0
  uint8_t c;
1518
0
  int return_code;
1519
1520
0
  return_code = read_escaped_char(yyscanner, &c, LEX_ENV->strict_escape);
1521
0
  if (return_code == VALID_ESCAPE_SEQUENCE)
1522
0
  {
1523
0
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1524
0
  }
1525
0
  else if (return_code == UNKNOWN_ESCAPE_SEQUENCE)
1526
0
  {
1527
0
    yywarning(yyscanner, lex_env, "unknown escape sequence");
1528
0
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1529
0
  }
1530
0
  else
1531
0
  {
1532
0
    yyerror(yyscanner, lex_env, "illegal escape sequence");
1533
0
    yyterminate();
1534
0
  }
1535
0
}
1536
0
  YY_BREAK
1537
0
case 27:
1538
0
YY_RULE_SETUP
1539
0
#line 451 "libyara/re_lexer.l"
1540
0
{
1541
1542
0
  if (yytext[0] >= 32 && yytext[0] < 127)
1543
0
  {
1544
    // A character class (i.e: [0-9a-f]) is represented by a 256-bits vector,
1545
    // here we set to 1 the vector's bit corresponding to the input character.
1546
1547
0
    LEX_ENV->re_class.bitmap[yytext[0] / 8] |= 1 << yytext[0] % 8;
1548
0
  }
1549
0
  else
1550
0
  {
1551
0
    yyerror(yyscanner, lex_env, "non-ascii character");
1552
0
    yyterminate();
1553
0
  }
1554
0
}
1555
0
  YY_BREAK
1556
0
case YY_STATE_EOF(char_class):
1557
0
#line 468 "libyara/re_lexer.l"
1558
0
{
1559
1560
  // End of regexp reached while scanning a character class.
1561
1562
0
  yyerror(yyscanner, lex_env, "missing terminating ] for character class");
1563
0
  yyterminate();
1564
0
}
1565
0
  YY_BREAK
1566
0
case 28:
1567
0
YY_RULE_SETUP
1568
0
#line 477 "libyara/re_lexer.l"
1569
0
{
1570
1571
0
  if (yytext[0] >= 32 && yytext[0] < 127)
1572
0
  {
1573
0
    return yytext[0];
1574
0
  }
1575
0
  else
1576
0
  {
1577
0
    yyerror(yyscanner, lex_env, "non-ascii character");
1578
0
    yyterminate();
1579
0
  }
1580
0
}
1581
0
  YY_BREAK
1582
0
case YY_STATE_EOF(INITIAL):
1583
0
#line 491 "libyara/re_lexer.l"
1584
0
{
1585
1586
0
  yyterminate();
1587
0
}
1588
0
  YY_BREAK
1589
0
case 29:
1590
0
YY_RULE_SETUP
1591
0
#line 496 "libyara/re_lexer.l"
1592
0
ECHO;
1593
0
  YY_BREAK
1594
0
#line 1594 "libyara/re_lexer.c"
1595
1596
0
  case YY_END_OF_BUFFER:
1597
0
    {
1598
    /* Amount of text matched not including the EOB char. */
1599
0
    int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
1600
1601
    /* Undo the effects of YY_DO_BEFORE_ACTION. */
1602
0
    *yy_cp = yyg->yy_hold_char;
1603
0
    YY_RESTORE_YY_MORE_OFFSET
1604
1605
0
    if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1606
0
      {
1607
      /* We're scanning a new file or input source.  It's
1608
       * possible that this happened because the user
1609
       * just pointed yyin at a new source and called
1610
       * yylex().  If so, then we have to assure
1611
       * consistency between YY_CURRENT_BUFFER and our
1612
       * globals.  Here is the right place to do so, because
1613
       * this is the first action (other than possibly a
1614
       * back-up) that will match for the new input source.
1615
       */
1616
0
      yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1617
0
      YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1618
0
      YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1619
0
      }
1620
1621
    /* Note that here we test for yy_c_buf_p "<=" to the position
1622
     * of the first EOB in the buffer, since yy_c_buf_p will
1623
     * already have been incremented past the NUL character
1624
     * (since all states make transitions on EOB to the
1625
     * end-of-buffer state).  Contrast this with the test
1626
     * in input().
1627
     */
1628
0
    if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1629
0
      { /* This was really a NUL. */
1630
0
      yy_state_type yy_next_state;
1631
1632
0
      yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
1633
1634
0
      yy_current_state = yy_get_previous_state( yyscanner );
1635
1636
      /* Okay, we're now positioned to make the NUL
1637
       * transition.  We couldn't have
1638
       * yy_get_previous_state() go ahead and do it
1639
       * for us because it doesn't know how to deal
1640
       * with the possibility of jamming (and we don't
1641
       * want to build jamming into it because then it
1642
       * will run more slowly).
1643
       */
1644
1645
0
      yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
1646
1647
0
      yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1648
1649
0
      if ( yy_next_state )
1650
0
        {
1651
        /* Consume the NUL. */
1652
0
        yy_cp = ++yyg->yy_c_buf_p;
1653
0
        yy_current_state = yy_next_state;
1654
0
        goto yy_match;
1655
0
        }
1656
1657
0
      else
1658
0
        {
1659
0
        yy_cp = yyg->yy_last_accepting_cpos;
1660
0
        yy_current_state = yyg->yy_last_accepting_state;
1661
0
        goto yy_find_action;
1662
0
        }
1663
0
      }
1664
1665
0
    else switch ( yy_get_next_buffer( yyscanner ) )
1666
0
      {
1667
0
      case EOB_ACT_END_OF_FILE:
1668
0
        {
1669
0
        yyg->yy_did_buffer_switch_on_eof = 0;
1670
1671
0
        if ( yywrap( yyscanner ) )
1672
0
          {
1673
          /* Note: because we've taken care in
1674
           * yy_get_next_buffer() to have set up
1675
           * yytext, we can now set up
1676
           * yy_c_buf_p so that if some total
1677
           * hoser (like flex itself) wants to
1678
           * call the scanner after we return the
1679
           * YY_NULL, it'll still work - another
1680
           * YY_NULL will get returned.
1681
           */
1682
0
          yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
1683
1684
0
          yy_act = YY_STATE_EOF(YY_START);
1685
0
          goto do_action;
1686
0
          }
1687
1688
0
        else
1689
0
          {
1690
0
          if ( ! yyg->yy_did_buffer_switch_on_eof )
1691
0
            YY_NEW_FILE;
1692
0
          }
1693
0
        break;
1694
0
        }
1695
1696
0
      case EOB_ACT_CONTINUE_SCAN:
1697
0
        yyg->yy_c_buf_p =
1698
0
          yyg->yytext_ptr + yy_amount_of_matched_text;
1699
1700
0
        yy_current_state = yy_get_previous_state( yyscanner );
1701
1702
0
        yy_cp = yyg->yy_c_buf_p;
1703
0
        yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1704
0
        goto yy_match;
1705
1706
0
      case EOB_ACT_LAST_MATCH:
1707
0
        yyg->yy_c_buf_p =
1708
0
        &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
1709
1710
0
        yy_current_state = yy_get_previous_state( yyscanner );
1711
1712
0
        yy_cp = yyg->yy_c_buf_p;
1713
0
        yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1714
0
        goto yy_find_action;
1715
0
      }
1716
0
    break;
1717
0
    }
1718
1719
0
  default:
1720
0
    YY_FATAL_ERROR(
1721
0
      "fatal flex scanner internal error--no action found" );
1722
0
  } /* end of action switch */
1723
0
    } /* end of scanning one token */
1724
0
  } /* end of user's declarations */
1725
0
} /* end of yylex */
1726
1727
/* yy_get_next_buffer - try to read in a new buffer
1728
 *
1729
 * Returns a code representing an action:
1730
 *  EOB_ACT_LAST_MATCH -
1731
 *  EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1732
 *  EOB_ACT_END_OF_FILE - end of file
1733
 */
1734
static int yy_get_next_buffer (yyscan_t yyscanner)
1735
0
{
1736
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1737
0
  char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1738
0
  char *source = yyg->yytext_ptr;
1739
0
  int number_to_move, i;
1740
0
  int ret_val;
1741
1742
0
  if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
1743
0
    YY_FATAL_ERROR(
1744
0
    "fatal flex scanner internal error--end of buffer missed" );
1745
1746
0
  if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1747
0
    { /* Don't try to fill the buffer, so this is an EOF. */
1748
0
    if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
1749
0
      {
1750
      /* We matched a single character, the EOB, so
1751
       * treat this as a final EOF.
1752
       */
1753
0
      return EOB_ACT_END_OF_FILE;
1754
0
      }
1755
1756
0
    else
1757
0
      {
1758
      /* We matched some text prior to the EOB, first
1759
       * process it.
1760
       */
1761
0
      return EOB_ACT_LAST_MATCH;
1762
0
      }
1763
0
    }
1764
1765
  /* Try to read more data. */
1766
1767
  /* First move last chars to start of buffer. */
1768
0
  number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
1769
1770
0
  for ( i = 0; i < number_to_move; ++i )
1771
0
    *(dest++) = *(source++);
1772
1773
0
  if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1774
    /* don't do the read, it's not guaranteed to return an EOF,
1775
     * just force an EOF
1776
     */
1777
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
1778
1779
0
  else
1780
0
    {
1781
0
      int num_to_read =
1782
0
      YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1783
1784
0
    while ( num_to_read <= 0 )
1785
0
      { /* Not enough room in the buffer - grow it. */
1786
1787
      /* just a shorter name for the current buffer */
1788
0
      YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1789
1790
0
      int yy_c_buf_p_offset =
1791
0
        (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
1792
1793
0
      if ( b->yy_is_our_buffer )
1794
0
        {
1795
0
        int new_size = b->yy_buf_size * 2;
1796
1797
0
        if ( new_size <= 0 )
1798
0
          b->yy_buf_size += b->yy_buf_size / 8;
1799
0
        else
1800
0
          b->yy_buf_size *= 2;
1801
1802
0
        b->yy_ch_buf = (char *)
1803
          /* Include room in for 2 EOB chars. */
1804
0
          yyrealloc( (void *) b->yy_ch_buf,
1805
0
               (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
1806
0
        }
1807
0
      else
1808
        /* Can't grow it, we don't own it. */
1809
0
        b->yy_ch_buf = NULL;
1810
1811
0
      if ( ! b->yy_ch_buf )
1812
0
        YY_FATAL_ERROR(
1813
0
        "fatal error - scanner input buffer overflow" );
1814
1815
0
      yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
1816
1817
0
      num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1818
0
            number_to_move - 1;
1819
1820
0
      }
1821
1822
0
    if ( num_to_read > YY_READ_BUF_SIZE )
1823
0
      num_to_read = YY_READ_BUF_SIZE;
1824
1825
    /* Read in more data. */
1826
0
    YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1827
0
      yyg->yy_n_chars, num_to_read );
1828
1829
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1830
0
    }
1831
1832
0
  if ( yyg->yy_n_chars == 0 )
1833
0
    {
1834
0
    if ( number_to_move == YY_MORE_ADJ )
1835
0
      {
1836
0
      ret_val = EOB_ACT_END_OF_FILE;
1837
0
      yyrestart( yyin  , yyscanner);
1838
0
      }
1839
1840
0
    else
1841
0
      {
1842
0
      ret_val = EOB_ACT_LAST_MATCH;
1843
0
      YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1844
0
        YY_BUFFER_EOF_PENDING;
1845
0
      }
1846
0
    }
1847
1848
0
  else
1849
0
    ret_val = EOB_ACT_CONTINUE_SCAN;
1850
1851
0
  if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1852
    /* Extend the array by 50%, plus the number we really need. */
1853
0
    int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
1854
0
    YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
1855
0
      (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
1856
0
    if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1857
0
      YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1858
    /* "- 2" to take care of EOB's */
1859
0
    YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
1860
0
  }
1861
1862
0
  yyg->yy_n_chars += number_to_move;
1863
0
  YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
1864
0
  YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
1865
1866
0
  yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1867
1868
0
  return ret_val;
1869
0
}
1870
1871
/* yy_get_previous_state - get the state just before the EOB char was reached */
1872
1873
    static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
1874
0
{
1875
0
  yy_state_type yy_current_state;
1876
0
  char *yy_cp;
1877
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1878
1879
0
  yy_current_state = yyg->yy_start;
1880
1881
0
  for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
1882
0
    {
1883
0
    YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1884
0
    if ( yy_accept[yy_current_state] )
1885
0
      {
1886
0
      yyg->yy_last_accepting_state = yy_current_state;
1887
0
      yyg->yy_last_accepting_cpos = yy_cp;
1888
0
      }
1889
0
    while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1890
0
      {
1891
0
      yy_current_state = (int) yy_def[yy_current_state];
1892
0
      if ( yy_current_state >= 47 )
1893
0
        yy_c = yy_meta[yy_c];
1894
0
      }
1895
0
    yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1896
0
    }
1897
1898
0
  return yy_current_state;
1899
0
}
1900
1901
/* yy_try_NUL_trans - try to make a transition on the NUL character
1902
 *
1903
 * synopsis
1904
 *  next_state = yy_try_NUL_trans( current_state );
1905
 */
1906
    static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state , yyscan_t yyscanner)
1907
0
{
1908
0
  int yy_is_jam;
1909
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
1910
0
  char *yy_cp = yyg->yy_c_buf_p;
1911
1912
0
  YY_CHAR yy_c = 1;
1913
0
  if ( yy_accept[yy_current_state] )
1914
0
    {
1915
0
    yyg->yy_last_accepting_state = yy_current_state;
1916
0
    yyg->yy_last_accepting_cpos = yy_cp;
1917
0
    }
1918
0
  while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1919
0
    {
1920
0
    yy_current_state = (int) yy_def[yy_current_state];
1921
0
    if ( yy_current_state >= 47 )
1922
0
      yy_c = yy_meta[yy_c];
1923
0
    }
1924
0
  yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1925
0
  yy_is_jam = (yy_current_state == 46);
1926
1927
0
  (void)yyg;
1928
0
  return yy_is_jam ? 0 : yy_current_state;
1929
0
}
1930
1931
#ifndef YY_NO_UNPUT
1932
1933
#endif
1934
1935
#ifndef YY_NO_INPUT
1936
#ifdef __cplusplus
1937
    static int yyinput (yyscan_t yyscanner)
1938
#else
1939
    static int input  (yyscan_t yyscanner)
1940
#endif
1941
1942
0
{
1943
0
  int c;
1944
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1945
1946
0
  *yyg->yy_c_buf_p = yyg->yy_hold_char;
1947
1948
0
  if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
1949
0
    {
1950
    /* yy_c_buf_p now points to the character we want to return.
1951
     * If this occurs *before* the EOB characters, then it's a
1952
     * valid NUL; if not, then we've hit the end of the buffer.
1953
     */
1954
0
    if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1955
      /* This was really a NUL. */
1956
0
      *yyg->yy_c_buf_p = '\0';
1957
1958
0
    else
1959
0
      { /* need more input */
1960
0
      int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
1961
0
      ++yyg->yy_c_buf_p;
1962
1963
0
      switch ( yy_get_next_buffer( yyscanner ) )
1964
0
        {
1965
0
        case EOB_ACT_LAST_MATCH:
1966
          /* This happens because yy_g_n_b()
1967
           * sees that we've accumulated a
1968
           * token and flags that we need to
1969
           * try matching the token before
1970
           * proceeding.  But for input(),
1971
           * there's no matching to consider.
1972
           * So convert the EOB_ACT_LAST_MATCH
1973
           * to EOB_ACT_END_OF_FILE.
1974
           */
1975
1976
          /* Reset buffer status. */
1977
0
          yyrestart( yyin , yyscanner);
1978
1979
          /*FALLTHROUGH*/
1980
1981
0
        case EOB_ACT_END_OF_FILE:
1982
0
          {
1983
0
          if ( yywrap( yyscanner ) )
1984
0
            return 0;
1985
1986
0
          if ( ! yyg->yy_did_buffer_switch_on_eof )
1987
0
            YY_NEW_FILE;
1988
#ifdef __cplusplus
1989
          return yyinput(yyscanner);
1990
#else
1991
0
          return input(yyscanner);
1992
0
#endif
1993
0
          }
1994
1995
0
        case EOB_ACT_CONTINUE_SCAN:
1996
0
          yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
1997
0
          break;
1998
0
        }
1999
0
      }
2000
0
    }
2001
2002
0
  c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
2003
0
  *yyg->yy_c_buf_p = '\0';  /* preserve yytext */
2004
0
  yyg->yy_hold_char = *++yyg->yy_c_buf_p;
2005
2006
0
  if ( c == '\n' )
2007
    
2008
0
    do{ yylineno++;
2009
0
        yycolumn=0;
2010
0
    }while(0)
2011
0
;
2012
2013
0
  return c;
2014
0
}
2015
#endif  /* ifndef YY_NO_INPUT */
2016
2017
/** Immediately switch to a different input stream.
2018
 * @param input_file A readable stream.
2019
 * @param yyscanner The scanner object.
2020
 * @note This function does not reset the start condition to @c INITIAL .
2021
 */
2022
    void yyrestart  (FILE * input_file , yyscan_t yyscanner)
2023
0
{
2024
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2025
2026
0
  if ( ! YY_CURRENT_BUFFER ){
2027
0
        yyensure_buffer_stack (yyscanner);
2028
0
    YY_CURRENT_BUFFER_LVALUE =
2029
0
            yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
2030
0
  }
2031
2032
0
  yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
2033
0
  yy_load_buffer_state( yyscanner );
2034
0
}
2035
2036
/** Switch to a different input buffer.
2037
 * @param new_buffer The new input buffer.
2038
 * @param yyscanner The scanner object.
2039
 */
2040
    void yy_switch_to_buffer  (YY_BUFFER_STATE  new_buffer , yyscan_t yyscanner)
2041
0
{
2042
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2043
2044
  /* TODO. We should be able to replace this entire function body
2045
   * with
2046
   *    yypop_buffer_state();
2047
   *    yypush_buffer_state(new_buffer);
2048
     */
2049
0
  yyensure_buffer_stack (yyscanner);
2050
0
  if ( YY_CURRENT_BUFFER == new_buffer )
2051
0
    return;
2052
2053
0
  if ( YY_CURRENT_BUFFER )
2054
0
    {
2055
    /* Flush out information for old buffer. */
2056
0
    *yyg->yy_c_buf_p = yyg->yy_hold_char;
2057
0
    YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
2058
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
2059
0
    }
2060
2061
0
  YY_CURRENT_BUFFER_LVALUE = new_buffer;
2062
0
  yy_load_buffer_state( yyscanner );
2063
2064
  /* We don't actually know whether we did this switch during
2065
   * EOF (yywrap()) processing, but the only time this flag
2066
   * is looked at is after yywrap() is called, so it's safe
2067
   * to go ahead and always set it.
2068
   */
2069
0
  yyg->yy_did_buffer_switch_on_eof = 1;
2070
0
}
2071
2072
static void yy_load_buffer_state  (yyscan_t yyscanner)
2073
0
{
2074
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2075
0
  yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
2076
0
  yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
2077
0
  yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
2078
0
  yyg->yy_hold_char = *yyg->yy_c_buf_p;
2079
0
}
2080
2081
/** Allocate and initialize an input buffer state.
2082
 * @param file A readable stream.
2083
 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
2084
 * @param yyscanner The scanner object.
2085
 * @return the allocated buffer state.
2086
 */
2087
    YY_BUFFER_STATE yy_create_buffer  (FILE * file, int  size , yyscan_t yyscanner)
2088
0
{
2089
0
  YY_BUFFER_STATE b;
2090
    
2091
0
  b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
2092
0
  if ( ! b )
2093
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
2094
2095
0
  b->yy_buf_size = size;
2096
2097
  /* yy_ch_buf has to be 2 characters longer than the size given because
2098
   * we need to put in 2 end-of-buffer characters.
2099
   */
2100
0
  b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
2101
0
  if ( ! b->yy_ch_buf )
2102
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
2103
2104
0
  b->yy_is_our_buffer = 1;
2105
2106
0
  yy_init_buffer( b, file , yyscanner);
2107
2108
0
  return b;
2109
0
}
2110
2111
/** Destroy the buffer.
2112
 * @param b a buffer created with yy_create_buffer()
2113
 * @param yyscanner The scanner object.
2114
 */
2115
    void yy_delete_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
2116
0
{
2117
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2118
2119
0
  if ( ! b )
2120
0
    return;
2121
2122
0
  if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
2123
0
    YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
2124
2125
0
  if ( b->yy_is_our_buffer )
2126
0
    yyfree( (void *) b->yy_ch_buf , yyscanner );
2127
2128
0
  yyfree( (void *) b , yyscanner );
2129
0
}
2130
2131
/* Initializes or reinitializes a buffer.
2132
 * This function is sometimes called more than once on the same buffer,
2133
 * such as during a yyrestart() or at EOF.
2134
 */
2135
    static void yy_init_buffer  (YY_BUFFER_STATE  b, FILE * file , yyscan_t yyscanner)
2136
2137
0
{
2138
0
  int oerrno = errno;
2139
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2140
2141
0
  yy_flush_buffer( b , yyscanner);
2142
2143
0
  b->yy_input_file = file;
2144
0
  b->yy_fill_buffer = 1;
2145
2146
    /* If b is the current buffer, then yy_init_buffer was _probably_
2147
     * called from yyrestart() or through yy_get_next_buffer.
2148
     * In that case, we don't want to reset the lineno or column.
2149
     */
2150
0
    if (b != YY_CURRENT_BUFFER){
2151
0
        b->yy_bs_lineno = 1;
2152
0
        b->yy_bs_column = 0;
2153
0
    }
2154
2155
0
        b->yy_is_interactive = 0;
2156
    
2157
0
  errno = oerrno;
2158
0
}
2159
2160
/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
2161
 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
2162
 * @param yyscanner The scanner object.
2163
 */
2164
    void yy_flush_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
2165
0
{
2166
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2167
0
  if ( ! b )
2168
0
    return;
2169
2170
0
  b->yy_n_chars = 0;
2171
2172
  /* We always need two end-of-buffer characters.  The first causes
2173
   * a transition to the end-of-buffer state.  The second causes
2174
   * a jam in that state.
2175
   */
2176
0
  b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
2177
0
  b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
2178
2179
0
  b->yy_buf_pos = &b->yy_ch_buf[0];
2180
2181
0
  b->yy_at_bol = 1;
2182
0
  b->yy_buffer_status = YY_BUFFER_NEW;
2183
2184
0
  if ( b == YY_CURRENT_BUFFER )
2185
0
    yy_load_buffer_state( yyscanner );
2186
0
}
2187
2188
/** Pushes the new state onto the stack. The new state becomes
2189
 *  the current state. This function will allocate the stack
2190
 *  if necessary.
2191
 *  @param new_buffer The new state.
2192
 *  @param yyscanner The scanner object.
2193
 */
2194
void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
2195
0
{
2196
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2197
0
  if (new_buffer == NULL)
2198
0
    return;
2199
2200
0
  yyensure_buffer_stack(yyscanner);
2201
2202
  /* This block is copied from yy_switch_to_buffer. */
2203
0
  if ( YY_CURRENT_BUFFER )
2204
0
    {
2205
    /* Flush out information for old buffer. */
2206
0
    *yyg->yy_c_buf_p = yyg->yy_hold_char;
2207
0
    YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
2208
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
2209
0
    }
2210
2211
  /* Only push if top exists. Otherwise, replace top. */
2212
0
  if (YY_CURRENT_BUFFER)
2213
0
    yyg->yy_buffer_stack_top++;
2214
0
  YY_CURRENT_BUFFER_LVALUE = new_buffer;
2215
2216
  /* copied from yy_switch_to_buffer. */
2217
0
  yy_load_buffer_state( yyscanner );
2218
0
  yyg->yy_did_buffer_switch_on_eof = 1;
2219
0
}
2220
2221
/** Removes and deletes the top of the stack, if present.
2222
 *  The next element becomes the new top.
2223
 *  @param yyscanner The scanner object.
2224
 */
2225
void yypop_buffer_state (yyscan_t yyscanner)
2226
0
{
2227
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2228
0
  if (!YY_CURRENT_BUFFER)
2229
0
    return;
2230
2231
0
  yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner);
2232
0
  YY_CURRENT_BUFFER_LVALUE = NULL;
2233
0
  if (yyg->yy_buffer_stack_top > 0)
2234
0
    --yyg->yy_buffer_stack_top;
2235
2236
0
  if (YY_CURRENT_BUFFER) {
2237
0
    yy_load_buffer_state( yyscanner );
2238
0
    yyg->yy_did_buffer_switch_on_eof = 1;
2239
0
  }
2240
0
}
2241
2242
/* Allocates the stack if it does not exist.
2243
 *  Guarantees space for at least one push.
2244
 */
2245
static void yyensure_buffer_stack (yyscan_t yyscanner)
2246
0
{
2247
0
  yy_size_t num_to_alloc;
2248
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2249
2250
0
  if (!yyg->yy_buffer_stack) {
2251
2252
    /* First allocation is just for 2 elements, since we don't know if this
2253
     * scanner will even need a stack. We use 2 instead of 1 to avoid an
2254
     * immediate realloc on the next call.
2255
         */
2256
0
      num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
2257
0
    yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
2258
0
                (num_to_alloc * sizeof(struct yy_buffer_state*)
2259
0
                , yyscanner);
2260
0
    if ( ! yyg->yy_buffer_stack )
2261
0
      YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2262
2263
0
    memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
2264
2265
0
    yyg->yy_buffer_stack_max = num_to_alloc;
2266
0
    yyg->yy_buffer_stack_top = 0;
2267
0
    return;
2268
0
  }
2269
2270
0
  if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
2271
2272
    /* Increase the buffer to prepare for a possible push. */
2273
0
    yy_size_t grow_size = 8 /* arbitrary grow size */;
2274
2275
0
    num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
2276
0
    yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc
2277
0
                (yyg->yy_buffer_stack,
2278
0
                num_to_alloc * sizeof(struct yy_buffer_state*)
2279
0
                , yyscanner);
2280
0
    if ( ! yyg->yy_buffer_stack )
2281
0
      YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2282
2283
    /* zero only the new slots.*/
2284
0
    memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
2285
0
    yyg->yy_buffer_stack_max = num_to_alloc;
2286
0
  }
2287
0
}
2288
2289
/** Setup the input buffer state to scan directly from a user-specified character buffer.
2290
 * @param base the character buffer
2291
 * @param size the size in bytes of the character buffer
2292
 * @param yyscanner The scanner object.
2293
 * @return the newly allocated buffer state object.
2294
 */
2295
YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size , yyscan_t yyscanner)
2296
0
{
2297
0
  YY_BUFFER_STATE b;
2298
    
2299
0
  if ( size < 2 ||
2300
0
       base[size-2] != YY_END_OF_BUFFER_CHAR ||
2301
0
       base[size-1] != YY_END_OF_BUFFER_CHAR )
2302
    /* They forgot to leave room for the EOB's. */
2303
0
    return NULL;
2304
2305
0
  b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
2306
0
  if ( ! b )
2307
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
2308
2309
0
  b->yy_buf_size = (int) (size - 2);  /* "- 2" to take care of EOB's */
2310
0
  b->yy_buf_pos = b->yy_ch_buf = base;
2311
0
  b->yy_is_our_buffer = 0;
2312
0
  b->yy_input_file = NULL;
2313
0
  b->yy_n_chars = b->yy_buf_size;
2314
0
  b->yy_is_interactive = 0;
2315
0
  b->yy_at_bol = 1;
2316
0
  b->yy_fill_buffer = 0;
2317
0
  b->yy_buffer_status = YY_BUFFER_NEW;
2318
2319
0
  yy_switch_to_buffer( b , yyscanner );
2320
2321
0
  return b;
2322
0
}
2323
2324
/** Setup the input buffer state to scan a string. The next call to yylex() will
2325
 * scan from a @e copy of @a str.
2326
 * @param yystr a NUL-terminated string to scan
2327
 * @param yyscanner The scanner object.
2328
 * @return the newly allocated buffer state object.
2329
 * @note If you want to scan bytes that may contain NUL values, then use
2330
 *       yy_scan_bytes() instead.
2331
 */
2332
YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
2333
0
{
2334
    
2335
0
  return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
2336
0
}
2337
2338
/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
2339
 * scan from a @e copy of @a bytes.
2340
 * @param yybytes the byte buffer to scan
2341
 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
2342
 * @param yyscanner The scanner object.
2343
 * @return the newly allocated buffer state object.
2344
 */
2345
YY_BUFFER_STATE yy_scan_bytes  (const char * yybytes, int  _yybytes_len , yyscan_t yyscanner)
2346
0
{
2347
0
  YY_BUFFER_STATE b;
2348
0
  char *buf;
2349
0
  yy_size_t n;
2350
0
  int i;
2351
    
2352
  /* Get memory for full buffer, including space for trailing EOB's. */
2353
0
  n = (yy_size_t) (_yybytes_len + 2);
2354
0
  buf = (char *) yyalloc( n , yyscanner );
2355
0
  if ( ! buf )
2356
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
2357
2358
0
  for ( i = 0; i < _yybytes_len; ++i )
2359
0
    buf[i] = yybytes[i];
2360
2361
0
  buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2362
2363
0
  b = yy_scan_buffer( buf, n , yyscanner);
2364
0
  if ( ! b )
2365
0
    YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
2366
2367
  /* It's okay to grow etc. this buffer, and we should throw it
2368
   * away when we're done.
2369
   */
2370
0
  b->yy_is_our_buffer = 1;
2371
2372
0
  return b;
2373
0
}
2374
2375
#ifndef YY_EXIT_FAILURE
2376
#define YY_EXIT_FAILURE 2
2377
#endif
2378
2379
static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
2380
0
{
2381
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2382
0
  (void)yyg;
2383
0
  fprintf( stderr, "%s\n", msg );
2384
0
  exit( YY_EXIT_FAILURE );
2385
0
}
2386
2387
/* Redefine yyless() so it works in section 3 code. */
2388
2389
#undef yyless
2390
#define yyless(n) \
2391
  do \
2392
    { \
2393
    /* Undo effects of setting up yytext. */ \
2394
        int yyless_macro_arg = (n); \
2395
        YY_LESS_LINENO(yyless_macro_arg);\
2396
    yytext[yyleng] = yyg->yy_hold_char; \
2397
    yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
2398
    yyg->yy_hold_char = *yyg->yy_c_buf_p; \
2399
    *yyg->yy_c_buf_p = '\0'; \
2400
    yyleng = yyless_macro_arg; \
2401
    } \
2402
  while ( 0 )
2403
2404
/* Accessor  methods (get/set functions) to struct members. */
2405
2406
/** Get the user-defined data for this scanner.
2407
 * @param yyscanner The scanner object.
2408
 */
2409
YY_EXTRA_TYPE yyget_extra  (yyscan_t yyscanner)
2410
0
{
2411
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2412
0
    return yyextra;
2413
0
}
2414
2415
/** Get the current line number.
2416
 * @param yyscanner The scanner object.
2417
 */
2418
int yyget_lineno  (yyscan_t yyscanner)
2419
0
{
2420
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2421
2422
0
        if (! YY_CURRENT_BUFFER)
2423
0
            return 0;
2424
    
2425
0
    return yylineno;
2426
0
}
2427
2428
/** Get the current column number.
2429
 * @param yyscanner The scanner object.
2430
 */
2431
int yyget_column  (yyscan_t yyscanner)
2432
0
{
2433
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2434
2435
0
        if (! YY_CURRENT_BUFFER)
2436
0
            return 0;
2437
    
2438
0
    return yycolumn;
2439
0
}
2440
2441
/** Get the input stream.
2442
 * @param yyscanner The scanner object.
2443
 */
2444
FILE *yyget_in  (yyscan_t yyscanner)
2445
0
{
2446
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2447
0
    return yyin;
2448
0
}
2449
2450
/** Get the output stream.
2451
 * @param yyscanner The scanner object.
2452
 */
2453
FILE *yyget_out  (yyscan_t yyscanner)
2454
0
{
2455
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2456
0
    return yyout;
2457
0
}
2458
2459
/** Get the length of the current token.
2460
 * @param yyscanner The scanner object.
2461
 */
2462
int yyget_leng  (yyscan_t yyscanner)
2463
0
{
2464
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2465
0
    return yyleng;
2466
0
}
2467
2468
/** Get the current token.
2469
 * @param yyscanner The scanner object.
2470
 */
2471
2472
char *yyget_text  (yyscan_t yyscanner)
2473
0
{
2474
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2475
0
    return yytext;
2476
0
}
2477
2478
/** Set the user-defined data. This data is never touched by the scanner.
2479
 * @param user_defined The data to be associated with this scanner.
2480
 * @param yyscanner The scanner object.
2481
 */
2482
void yyset_extra (YY_EXTRA_TYPE  user_defined , yyscan_t yyscanner)
2483
0
{
2484
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2485
0
    yyextra = user_defined ;
2486
0
}
2487
2488
/** Set the current line number.
2489
 * @param _line_number line number
2490
 * @param yyscanner The scanner object.
2491
 */
2492
void yyset_lineno (int  _line_number , yyscan_t yyscanner)
2493
0
{
2494
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2495
2496
        /* lineno is only valid if an input buffer exists. */
2497
0
        if (! YY_CURRENT_BUFFER )
2498
0
           YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
2499
    
2500
0
    yylineno = _line_number;
2501
0
}
2502
2503
/** Set the current column.
2504
 * @param _column_no column number
2505
 * @param yyscanner The scanner object.
2506
 */
2507
void yyset_column (int  _column_no , yyscan_t yyscanner)
2508
0
{
2509
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2510
2511
        /* column is only valid if an input buffer exists. */
2512
0
        if (! YY_CURRENT_BUFFER )
2513
0
           YY_FATAL_ERROR( "yyset_column called with no buffer" );
2514
    
2515
0
    yycolumn = _column_no;
2516
0
}
2517
2518
/** Set the input stream. This does not discard the current
2519
 * input buffer.
2520
 * @param _in_str A readable stream.
2521
 * @param yyscanner The scanner object.
2522
 * @see yy_switch_to_buffer
2523
 */
2524
void yyset_in (FILE *  _in_str , yyscan_t yyscanner)
2525
0
{
2526
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2527
0
    yyin = _in_str ;
2528
0
}
2529
2530
void yyset_out (FILE *  _out_str , yyscan_t yyscanner)
2531
0
{
2532
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2533
0
    yyout = _out_str ;
2534
0
}
2535
2536
int yyget_debug  (yyscan_t yyscanner)
2537
0
{
2538
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2539
0
    return yy_flex_debug;
2540
0
}
2541
2542
void yyset_debug (int  _bdebug , yyscan_t yyscanner)
2543
0
{
2544
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2545
0
    yy_flex_debug = _bdebug ;
2546
0
}
2547
2548
/* Accessor methods for yylval and yylloc */
2549
2550
YYSTYPE * yyget_lval  (yyscan_t yyscanner)
2551
0
{
2552
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2553
0
    return yylval;
2554
0
}
2555
2556
void yyset_lval (YYSTYPE *  yylval_param , yyscan_t yyscanner)
2557
0
{
2558
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2559
0
    yylval = yylval_param;
2560
0
}
2561
2562
/* User-visible API */
2563
2564
/* yylex_init is special because it creates the scanner itself, so it is
2565
 * the ONLY reentrant function that doesn't take the scanner as the last argument.
2566
 * That's why we explicitly handle the declaration, instead of using our macros.
2567
 */
2568
int yylex_init(yyscan_t* ptr_yy_globals)
2569
0
{
2570
0
    if (ptr_yy_globals == NULL){
2571
0
        errno = EINVAL;
2572
0
        return 1;
2573
0
    }
2574
2575
0
    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
2576
2577
0
    if (*ptr_yy_globals == NULL){
2578
0
        errno = ENOMEM;
2579
0
        return 1;
2580
0
    }
2581
2582
    /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
2583
0
    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2584
2585
0
    return yy_init_globals ( *ptr_yy_globals );
2586
0
}
2587
2588
/* yylex_init_extra has the same functionality as yylex_init, but follows the
2589
 * convention of taking the scanner as the last argument. Note however, that
2590
 * this is a *pointer* to a scanner, as it will be allocated by this call (and
2591
 * is the reason, too, why this function also must handle its own declaration).
2592
 * The user defined value in the first argument will be available to yyalloc in
2593
 * the yyextra field.
2594
 */
2595
int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals )
2596
0
{
2597
0
    struct yyguts_t dummy_yyguts;
2598
2599
0
    yyset_extra (yy_user_defined, &dummy_yyguts);
2600
2601
0
    if (ptr_yy_globals == NULL){
2602
0
        errno = EINVAL;
2603
0
        return 1;
2604
0
    }
2605
2606
0
    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
2607
2608
0
    if (*ptr_yy_globals == NULL){
2609
0
        errno = ENOMEM;
2610
0
        return 1;
2611
0
    }
2612
2613
    /* By setting to 0xAA, we expose bugs in
2614
    yy_init_globals. Leave at 0x00 for releases. */
2615
0
    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2616
2617
0
    yyset_extra (yy_user_defined, *ptr_yy_globals);
2618
2619
0
    return yy_init_globals ( *ptr_yy_globals );
2620
0
}
2621
2622
static int yy_init_globals (yyscan_t yyscanner)
2623
0
{
2624
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2625
    /* Initialization is the same as for the non-reentrant scanner.
2626
     * This function is called from yylex_destroy(), so don't allocate here.
2627
     */
2628
2629
0
    yyg->yy_buffer_stack = NULL;
2630
0
    yyg->yy_buffer_stack_top = 0;
2631
0
    yyg->yy_buffer_stack_max = 0;
2632
0
    yyg->yy_c_buf_p = NULL;
2633
0
    yyg->yy_init = 0;
2634
0
    yyg->yy_start = 0;
2635
2636
0
    yyg->yy_start_stack_ptr = 0;
2637
0
    yyg->yy_start_stack_depth = 0;
2638
0
    yyg->yy_start_stack =  NULL;
2639
2640
/* Defined in main.c */
2641
#ifdef YY_STDINIT
2642
    yyin = stdin;
2643
    yyout = stdout;
2644
#else
2645
0
    yyin = NULL;
2646
0
    yyout = NULL;
2647
0
#endif
2648
2649
    /* For future reference: Set errno on error, since we are called by
2650
     * yylex_init()
2651
     */
2652
0
    return 0;
2653
0
}
2654
2655
/* yylex_destroy is for both reentrant and non-reentrant scanners. */
2656
int yylex_destroy  (yyscan_t yyscanner)
2657
0
{
2658
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2659
2660
    /* Pop the buffer stack, destroying each element. */
2661
0
  while(YY_CURRENT_BUFFER){
2662
0
    yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
2663
0
    YY_CURRENT_BUFFER_LVALUE = NULL;
2664
0
    yypop_buffer_state(yyscanner);
2665
0
  }
2666
2667
  /* Destroy the stack itself. */
2668
0
  yyfree(yyg->yy_buffer_stack , yyscanner);
2669
0
  yyg->yy_buffer_stack = NULL;
2670
2671
    /* Destroy the start condition stack. */
2672
0
        yyfree( yyg->yy_start_stack , yyscanner );
2673
0
        yyg->yy_start_stack = NULL;
2674
2675
    /* Reset the globals. This is important in a non-reentrant scanner so the next time
2676
     * yylex() is called, initialization will occur. */
2677
0
    yy_init_globals( yyscanner);
2678
2679
    /* Destroy the main struct (reentrant only). */
2680
0
    yyfree ( yyscanner , yyscanner );
2681
0
    yyscanner = NULL;
2682
0
    return 0;
2683
0
}
2684
2685
/*
2686
 * Internal utility routines.
2687
 */
2688
2689
#ifndef yytext_ptr
2690
static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
2691
{
2692
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2693
  (void)yyg;
2694
2695
  int i;
2696
  for ( i = 0; i < n; ++i )
2697
    s1[i] = s2[i];
2698
}
2699
#endif
2700
2701
#ifdef YY_NEED_STRLEN
2702
static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
2703
{
2704
  int n;
2705
  for ( n = 0; s[n]; ++n )
2706
    ;
2707
2708
  return n;
2709
}
2710
#endif
2711
2712
void *yyalloc (yy_size_t  size , yyscan_t yyscanner)
2713
0
{
2714
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2715
0
  (void)yyg;
2716
0
  return malloc(size);
2717
0
}
2718
2719
void *yyrealloc  (void * ptr, yy_size_t  size , yyscan_t yyscanner)
2720
0
{
2721
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2722
0
  (void)yyg;
2723
2724
  /* The cast to (char *) in the following accommodates both
2725
   * implementations that use char* generic pointers, and those
2726
   * that use void* generic pointers.  It works with the latter
2727
   * because both ANSI C and C++ allow castless assignment from
2728
   * any pointer type to void*, and deal with argument conversions
2729
   * as though doing an assignment.
2730
   */
2731
0
  return realloc(ptr, size);
2732
0
}
2733
2734
void yyfree (void * ptr , yyscan_t yyscanner)
2735
0
{
2736
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2737
0
  (void)yyg;
2738
0
  free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
2739
0
}
2740
2741
#define YYTABLES_NAME "yytables"
2742
2743
#line 496 "libyara/re_lexer.l"
2744
2745
2746
int escaped_char_value(
2747
    char* text,
2748
    uint8_t* value,
2749
    bool strict_escape)
2750
0
{
2751
0
  unsigned int hex_value;
2752
0
  char hex[3];
2753
2754
0
  assert(text[0] == '\\');
2755
2756
0
  switch(text[1])
2757
0
  {
2758
0
  case 'x':
2759
0
    if (!isxdigit(text[2]) || !isxdigit(text[3]))
2760
0
      return 0;
2761
0
    hex[0] = text[2];
2762
0
    hex[1] = text[3];
2763
0
    hex[2] = '\0';
2764
0
    sscanf(hex, "%x", &hex_value);
2765
0
    *value = (uint8_t) hex_value;
2766
0
    break;
2767
2768
0
  case 'n':
2769
0
    *value = '\n';
2770
0
    break;
2771
2772
0
  case 't':
2773
0
    *value = '\t';
2774
0
    break;
2775
2776
0
  case 'r':
2777
0
    *value = '\r';
2778
0
    break;
2779
2780
0
  case 'f':
2781
0
    *value = '\f';
2782
0
    break;
2783
2784
0
  case 'a':
2785
0
    *value = '\a';
2786
0
    break;
2787
2788
  // Support metacharacters in escape sequences
2789
0
  case '\\':
2790
0
  case '^':
2791
0
  case '$':
2792
0
  case '.':
2793
0
  case '|':
2794
0
  case '(':
2795
0
  case ')':
2796
0
  case '[':
2797
0
  case ']':
2798
2799
  // Support other special characters that are used in rules and need to be escaped
2800
0
  case '*':
2801
0
  case '+':
2802
0
  case '?':
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
    *value = text[1];
2822
0
    break;
2823
0
  default:
2824
0
    *value = text[1];
2825
0
    if (strict_escape)
2826
0
      return UNKNOWN_ESCAPE_SEQUENCE;
2827
0
    return VALID_ESCAPE_SEQUENCE;
2828
0
  }
2829
2830
0
  return VALID_ESCAPE_SEQUENCE;
2831
0
}
2832
2833
2834
#ifdef __cplusplus
2835
#define RE_YY_INPUT yyinput
2836
#else
2837
0
#define RE_YY_INPUT input
2838
#endif
2839
2840
2841
int read_escaped_char(
2842
    yyscan_t yyscanner,
2843
    uint8_t* escaped_char,
2844
    bool strict_escape)
2845
0
{
2846
0
  char text[4] = {0, 0, 0, 0};
2847
2848
0
  text[0] = '\\';
2849
0
  text[1] = RE_YY_INPUT(yyscanner);
2850
2851
0
  if (text[1] == EOF || text[1] == 0)
2852
0
    return 0;
2853
2854
0
  if (text[1] == 'x')
2855
0
  {
2856
0
    text[2] = RE_YY_INPUT(yyscanner);
2857
2858
0
    if (text[2] == EOF || text[2] == 0)
2859
0
      return 0;
2860
2861
0
    text[3] = RE_YY_INPUT(yyscanner);
2862
2863
0
    if (text[3] == EOF || text[3] == 0)
2864
0
      return 0;
2865
0
  }
2866
2867
0
  return escaped_char_value(text, escaped_char, strict_escape);
2868
0
}
2869
2870
2871
//
2872
// yyfatal (actually named re_yyfatal because of the '%option prefix="re_yy"'
2873
// directive) is called when a fatal error occurs in the parser. When this
2874
// happens we are deep inside the parsing logic generated by flex/bison and
2875
// the only way to exit gracefully from there is using setjmp/longjmp.
2876
//
2877
void yyfatal(
2878
    yyscan_t yyscanner,
2879
    const char *error_message)
2880
0
{
2881
0
  jmp_buf* recovery_trampoline = (jmp_buf*) yr_thread_storage_get_value(
2882
0
      &yr_yyfatal_trampoline_tls);
2883
2884
0
  longjmp(*recovery_trampoline, 1);
2885
0
}
2886
2887
2888
void yyerror(
2889
    yyscan_t yyscanner,
2890
    RE_LEX_ENVIRONMENT* lex_env,
2891
    const char *error_message)
2892
0
{
2893
  // if lex_env->last_error was set to some error code before
2894
  // don't overwrite it, we are interested in the first error, not in
2895
  // subsequent errors like "syntax error, unexpected $end" caused by
2896
  // early parser termination.
2897
2898
0
  if (lex_env->last_error == ERROR_SUCCESS || lex_env->last_error == ERROR_UNKNOWN_ESCAPE_SEQUENCE)
2899
0
  {
2900
0
    lex_env->last_error = ERROR_INVALID_REGULAR_EXPRESSION;
2901
2902
0
    strlcpy(
2903
0
        lex_env->last_error_message,
2904
0
        error_message,
2905
0
        sizeof(lex_env->last_error_message));
2906
0
  }
2907
0
}
2908
2909
void yywarning(
2910
    yyscan_t yyscanner,
2911
    RE_LEX_ENVIRONMENT* lex_env,
2912
    const char *error_message)
2913
0
{
2914
  // Do not overwrite Errors
2915
  // print out warning only if there is not any other error beforehand
2916
2917
0
  if (lex_env->last_error == ERROR_SUCCESS)
2918
0
  {
2919
0
    lex_env->last_error = ERROR_UNKNOWN_ESCAPE_SEQUENCE;
2920
2921
0
    strlcpy(
2922
0
        lex_env->last_error_message,
2923
0
        error_message,
2924
0
        sizeof(lex_env->last_error_message));
2925
0
  }
2926
0
}
2927
2928
int yr_parse_re_string(
2929
  const char* re_string,
2930
  RE_AST** re_ast,
2931
  RE_ERROR* error,
2932
  int flags)
2933
0
{
2934
0
  yyscan_t yyscanner;
2935
0
  jmp_buf recovery_trampoline;
2936
0
  RE_LEX_ENVIRONMENT lex_env;
2937
2938
0
  lex_env.last_error = ERROR_SUCCESS;
2939
0
  if (flags & RE_PARSER_FLAG_ENABLE_STRICT_ESCAPE_SEQUENCES)
2940
0
    lex_env.strict_escape = true;
2941
0
   else
2942
0
    lex_env.strict_escape = false;
2943
0
  lex_env.last_error_message[0] = '\0';
2944
2945
0
  yr_thread_storage_set_value(
2946
0
      &yr_yyfatal_trampoline_tls,
2947
0
      &recovery_trampoline);
2948
2949
  // setjmp returns a non-zero value only when we are returning to this
2950
  // point via a call to longjmp to the recovery trampoline.
2951
0
  if (setjmp(recovery_trampoline) != 0)
2952
0
    return ERROR_INTERNAL_FATAL_ERROR;
2953
2954
0
  FAIL_ON_ERROR(yr_re_ast_create(re_ast));
2955
2956
0
  if (yylex_init(&yyscanner) != 0)
2957
0
  {
2958
0
    yr_re_ast_destroy(*re_ast);
2959
0
    *re_ast = NULL;
2960
0
    return ERROR_INSUFFICIENT_MEMORY;
2961
0
  }
2962
2963
0
  yyset_extra(*re_ast, yyscanner);
2964
0
  yy_scan_string(re_string, yyscanner);
2965
2966
0
  yyparse(yyscanner, &lex_env);
2967
0
  yylex_destroy(yyscanner);
2968
2969
0
  if (lex_env.last_error != ERROR_SUCCESS)
2970
0
  {
2971
0
    if (lex_env.last_error != ERROR_UNKNOWN_ESCAPE_SEQUENCE)
2972
0
    {
2973
0
      yr_re_ast_destroy(*re_ast);
2974
0
      *re_ast = NULL;
2975
0
    }
2976
2977
0
    strlcpy(
2978
0
        error->message,
2979
0
        lex_env.last_error_message,
2980
0
        sizeof(error->message));
2981
2982
0
    return lex_env.last_error;
2983
0
  }
2984
2985
0
  return ERROR_SUCCESS;
2986
0
}
2987