Coverage Report

Created: 2025-07-11 06:08

/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
26.2k
#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
26.2k
#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
26.2k
#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
26.2k
#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
131
#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
131
#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
52.7k
#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
26.2k
#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
26.2k
#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
26.2k
#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
131
#define yyrestart re_yyrestart
99
#endif
100
101
#ifdef yylex_init
102
#define re_yylex_init_ALREADY_DEFINED
103
#else
104
26.2k
#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
26.2k
#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
26.2k
#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
25.9k
#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
105k
#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
131k
#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
26.2k
#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
4.44M
#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
183k
#define yyin yyg->yyin_r
345
105k
#define yyout yyg->yyout_r
346
123k
#define yyextra yyg->yyextra_r
347
4.42M
#define yyleng yyg->yyleng_r
348
3.03M
#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
2.73k
#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
51.6k
#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
2.26M
#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
51.8k
#define EOB_ACT_END_OF_FILE 1
399
52.7k
#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
78.4k
#define YY_BUFFER_NEW 0
487
25.8k
#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
210k
#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
510
210k
                          ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
511
210k
                          : 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
601k
#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
25.9k
#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
2.48M
#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
2.19M
  yyg->yytext_ptr = yy_bp; \
579
2.19M
  yyleng = (int) (yy_cp - yy_bp); \
580
2.19M
  yyg->yy_hold_char = *yy_cp; \
581
2.19M
  *yy_cp = '\0'; \
582
2.19M
  yyg->yy_c_buf_p = yy_cp;
583
#define YY_NUM_RULES 29
584
4.48M
#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
130k
#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
1.24k
#define INITIAL 0
809
1.49k
#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
4.01M
    #    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
26.2k
#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
20.2k
#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
2.14M
{
1045
2.14M
  yy_state_type yy_current_state;
1046
2.14M
  char *yy_cp, *yy_bp;
1047
2.14M
  int yy_act;
1048
2.14M
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1049
1050
2.14M
    yylval = yylval_param;
1051
1052
2.14M
  if ( !yyg->yy_init )
1053
26.2k
    {
1054
26.2k
    yyg->yy_init = 1;
1055
1056
#ifdef YY_USER_INIT
1057
    YY_USER_INIT;
1058
#endif
1059
1060
26.2k
    if ( ! yyg->yy_start )
1061
26.2k
      yyg->yy_start = 1; /* first start state */
1062
1063
26.2k
    if ( ! yyin )
1064
26.2k
      yyin = stdin;
1065
1066
26.2k
    if ( ! yyout )
1067
26.2k
      yyout = stdout;
1068
1069
26.2k
    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
26.2k
    yy_load_buffer_state( yyscanner );
1076
26.2k
    }
1077
1078
2.14M
  {
1079
2.14M
#line 114 "libyara/re_lexer.l"
1080
1081
1082
2.14M
#line 1082 "libyara/re_lexer.c"
1083
1084
2.16M
  while ( /*CONSTCOND*/1 )    /* loops until end-of-file is reached */
1085
2.16M
    {
1086
2.16M
    yy_cp = yyg->yy_c_buf_p;
1087
1088
    /* Support of yytext. */
1089
2.16M
    *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
2.16M
    yy_bp = yy_cp;
1095
1096
2.16M
    yy_current_state = yyg->yy_start;
1097
2.16M
yy_match:
1098
2.16M
    do
1099
4.40M
      {
1100
4.40M
      YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
1101
4.40M
      if ( yy_accept[yy_current_state] )
1102
2.21M
        {
1103
2.21M
        yyg->yy_last_accepting_state = yy_current_state;
1104
2.21M
        yyg->yy_last_accepting_cpos = yy_cp;
1105
2.21M
        }
1106
7.72M
      while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1107
3.31M
        {
1108
3.31M
        yy_current_state = (int) yy_def[yy_current_state];
1109
3.31M
        if ( yy_current_state >= 47 )
1110
1.15M
          yy_c = yy_meta[yy_c];
1111
3.31M
        }
1112
4.40M
      yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1113
4.40M
      ++yy_cp;
1114
4.40M
      }
1115
4.40M
    while ( yy_current_state != 46 );
1116
2.16M
    yy_cp = yyg->yy_last_accepting_cpos;
1117
2.16M
    yy_current_state = yyg->yy_last_accepting_state;
1118
1119
2.19M
yy_find_action:
1120
2.19M
    yy_act = yy_accept[yy_current_state];
1121
1122
2.19M
    YY_DO_BEFORE_ACTION;
1123
1124
2.19M
    if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
1125
1.11M
      {
1126
1.11M
      int yyl;
1127
2.23M
      for ( yyl = 0; yyl < yyleng; ++yyl )
1128
1.11M
        if ( yytext[yyl] == '\n' )
1129
          
1130
0
    do{ yylineno++;
1131
0
        yycolumn=0;
1132
0
    }while(0)
1133
1.11M
;
1134
1.11M
      }
1135
1136
2.21M
do_action:  /* This label is used only to access EOF actions. */
1137
1138
2.21M
    switch ( yy_act )
1139
2.21M
  { /* beginning of action switch */
1140
382
      case 0: /* must back up */
1141
      /* undo the effects of YY_DO_BEFORE_ACTION */
1142
382
      *yy_cp = yyg->yy_hold_char;
1143
382
      yy_cp = yyg->yy_last_accepting_cpos;
1144
382
      yy_current_state = yyg->yy_last_accepting_state;
1145
382
      goto yy_find_action;
1146
1147
5.02k
case 1:
1148
5.02k
YY_RULE_SETUP
1149
5.02k
#line 116 "libyara/re_lexer.l"
1150
5.02k
{
1151
1152
  // Examples: {3,8} {3, 8}, {3 ,8} {3 , 8} {0,5} {,5} {7,}
1153
1154
5.02k
  int hi_bound;
1155
5.02k
  int lo_bound = atoi(yytext + 1);
1156
1157
5.02k
  char* comma = strchr(yytext, ',');
1158
5.02k
  char* hi_bound_ptr = comma + 1;
1159
1160
  // Skip spaces after the comma, if any.
1161
5.02k
  while (*hi_bound_ptr == ' ') hi_bound_ptr++;
1162
1163
5.02k
  if (*hi_bound_ptr == '}')
1164
4.73k
    hi_bound = RE_MAX_RANGE;
1165
290
  else
1166
290
    hi_bound = atoi(hi_bound_ptr);
1167
1168
5.02k
  if (hi_bound > RE_MAX_RANGE)
1169
12
  {
1170
12
    yyerror(yyscanner, lex_env, "repeat interval too large");
1171
12
    yyterminate();
1172
12
  }
1173
1174
5.00k
  if (hi_bound < lo_bound || hi_bound < 0 || lo_bound < 0)
1175
22
  {
1176
22
    yyerror(yyscanner, lex_env, "bad repeat interval");
1177
22
    yyterminate();
1178
22
  }
1179
1180
4.98k
  yylval->range = (hi_bound << 16) | lo_bound;
1181
1182
4.98k
  return _RANGE_;
1183
5.00k
}
1184
0
  YY_BREAK
1185
2.28k
case 2:
1186
2.28k
YY_RULE_SETUP
1187
2.28k
#line 152 "libyara/re_lexer.l"
1188
2.28k
{
1189
1190
  // Example: {10}
1191
1192
2.28k
  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
2.28k
  if (value > RE_MAX_RANGE || value < 0)
1198
60
  {
1199
60
    yyerror(yyscanner, lex_env, "repeat interval too large");
1200
60
    yyterminate();
1201
60
  }
1202
1203
2.22k
  yylval->range = (value << 16) | value;
1204
1205
2.22k
  return _RANGE_;
1206
2.28k
}
1207
0
  YY_BREAK
1208
203
case 3:
1209
203
YY_RULE_SETUP
1210
203
#line 173 "libyara/re_lexer.l"
1211
203
{
1212
1213
  // Start of a negated character class. Example: [^abcd]
1214
1215
203
  BEGIN(char_class);
1216
203
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1217
203
  LEX_ENV->re_class.negated = true;
1218
203
}
1219
203
  YY_BREAK
1220
5
case 4:
1221
5
YY_RULE_SETUP
1222
5
#line 182 "libyara/re_lexer.l"
1223
5
{
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
5
  BEGIN(char_class);
1230
5
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1231
5
  LEX_ENV->re_class.negated = true;
1232
5
  LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8;
1233
5
}
1234
5
  YY_BREAK
1235
448
case 5:
1236
448
YY_RULE_SETUP
1237
448
#line 195 "libyara/re_lexer.l"
1238
448
{
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
448
  BEGIN(char_class);
1245
448
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1246
448
  LEX_ENV->re_class.negated = false;
1247
448
  LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8;
1248
448
}
1249
448
  YY_BREAK
1250
835
case 6:
1251
835
YY_RULE_SETUP
1252
835
#line 208 "libyara/re_lexer.l"
1253
835
{
1254
1255
  // Start of character class. Example: [abcd]
1256
1257
835
  BEGIN(char_class);
1258
835
  memset(LEX_ENV->re_class.bitmap, 0, 32);
1259
835
  LEX_ENV->re_class.negated = false;
1260
835
}
1261
835
  YY_BREAK
1262
1.11M
case 7:
1263
/* rule 7 can match eol */
1264
1.11M
YY_RULE_SETUP
1265
1.11M
#line 218 "libyara/re_lexer.l"
1266
1.11M
{
1267
1268
  // Any non-special character is passed as a CHAR token to the scanner.
1269
1270
1.11M
  yylval->integer = yytext[0];
1271
1.11M
  return _CHAR_;
1272
2.28k
}
1273
0
  YY_BREAK
1274
186
case 8:
1275
186
YY_RULE_SETUP
1276
186
#line 227 "libyara/re_lexer.l"
1277
186
{
1278
186
  return _WORD_CHAR_;
1279
2.28k
}
1280
0
  YY_BREAK
1281
572
case 9:
1282
572
YY_RULE_SETUP
1283
572
#line 232 "libyara/re_lexer.l"
1284
572
{
1285
572
  return _NON_WORD_CHAR_;
1286
2.28k
}
1287
0
  YY_BREAK
1288
1.50k
case 10:
1289
1.50k
YY_RULE_SETUP
1290
1.50k
#line 237 "libyara/re_lexer.l"
1291
1.50k
{
1292
1.50k
  return _SPACE_;
1293
2.28k
}
1294
0
  YY_BREAK
1295
407
case 11:
1296
407
YY_RULE_SETUP
1297
407
#line 242 "libyara/re_lexer.l"
1298
407
{
1299
407
  return _NON_SPACE_;
1300
2.28k
}
1301
0
  YY_BREAK
1302
453
case 12:
1303
453
YY_RULE_SETUP
1304
453
#line 247 "libyara/re_lexer.l"
1305
453
{
1306
453
  return _DIGIT_;
1307
2.28k
}
1308
0
  YY_BREAK
1309
152
case 13:
1310
152
YY_RULE_SETUP
1311
152
#line 252 "libyara/re_lexer.l"
1312
152
{
1313
152
  return _NON_DIGIT_;
1314
2.28k
}
1315
0
  YY_BREAK
1316
398
case 14:
1317
398
YY_RULE_SETUP
1318
398
#line 257 "libyara/re_lexer.l"
1319
398
{
1320
398
  return _WORD_BOUNDARY_;
1321
2.28k
}
1322
0
  YY_BREAK
1323
147
case 15:
1324
147
YY_RULE_SETUP
1325
147
#line 261 "libyara/re_lexer.l"
1326
147
{
1327
147
  return _NON_WORD_BOUNDARY_;
1328
2.28k
}
1329
0
  YY_BREAK
1330
21
case 16:
1331
21
YY_RULE_SETUP
1332
21
#line 266 "libyara/re_lexer.l"
1333
21
{
1334
1335
21
  yyerror(yyscanner, lex_env, "backreferences are not allowed");
1336
21
  yyterminate();
1337
2.28k
}
1338
0
  YY_BREAK
1339
748k
case 17:
1340
748k
YY_RULE_SETUP
1341
748k
#line 273 "libyara/re_lexer.l"
1342
748k
{
1343
1344
748k
  uint8_t c;
1345
748k
  int return_code;
1346
1347
748k
  return_code = read_escaped_char(yyscanner, &c, LEX_ENV->strict_escape);
1348
748k
  if (return_code == VALID_ESCAPE_SEQUENCE)
1349
748k
  {
1350
748k
    yylval->integer = c;
1351
748k
    return _CHAR_;
1352
748k
  }
1353
110
  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
110
  else
1360
110
  {
1361
110
    yyerror(yyscanner, lex_env, "illegal escape sequence");
1362
110
    yyterminate();
1363
110
  }
1364
748k
}
1365
0
  YY_BREAK
1366
1.24k
case 18:
1367
1.24k
YY_RULE_SETUP
1368
1.24k
#line 298 "libyara/re_lexer.l"
1369
1.24k
{
1370
1371
  // End of character class.
1372
1.24k
  yylval->re_class = (RE_CLASS*) yr_malloc(sizeof(RE_CLASS));
1373
1.24k
  memcpy(yylval->re_class->bitmap, LEX_ENV->re_class.bitmap, 32);
1374
1375
1.24k
  yylval->re_class->negated = LEX_ENV->re_class.negated;
1376
1377
1.24k
  BEGIN(INITIAL);
1378
1.24k
  return _CLASS_;
1379
748k
}
1380
0
  YY_BREAK
1381
2.15k
case 19:
1382
/* rule 19 can match eol */
1383
2.15k
YY_RULE_SETUP
1384
2.15k
#line 312 "libyara/re_lexer.l"
1385
2.15k
{
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
2.15k
  uint16_t c;
1409
2.15k
  uint8_t start = yytext[0];
1410
2.15k
  uint8_t end = yytext[2];
1411
1412
2.15k
  if (start == '\\')
1413
966
  {
1414
966
    if (!escaped_char_value(yytext, &start, LEX_ENV->strict_escape))
1415
18
    {
1416
18
      yyerror(yyscanner, lex_env, "illegal escape sequence");
1417
18
      yyterminate();
1418
18
    }
1419
1420
948
    if (yytext[1] == 'x')
1421
256
      end = yytext[5];
1422
692
    else
1423
692
      end = yytext[3];
1424
948
  }
1425
1426
2.13k
  if (end == '\\')
1427
853
  {
1428
853
    if (!read_escaped_char(yyscanner, &end, LEX_ENV->strict_escape))
1429
87
    {
1430
87
      yyerror(yyscanner, lex_env, "illegal escape sequence");
1431
87
      yyterminate();
1432
87
    }
1433
853
  }
1434
1435
2.04k
  if (end < start)
1436
40
  {
1437
40
    yyerror(yyscanner, lex_env, "bad character range");
1438
40
    yyterminate();
1439
40
  }
1440
1441
78.8k
  for (c = start; c <= end; c++)
1442
76.8k
  {
1443
76.8k
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1444
76.8k
  }
1445
2.00k
}
1446
2.00k
  YY_BREAK
1447
718
case 20:
1448
718
YY_RULE_SETUP
1449
718
#line 375 "libyara/re_lexer.l"
1450
718
{
1451
1452
23.6k
  for (int i = 0; i < 32; i++)
1453
22.9k
    LEX_ENV->re_class.bitmap[i] |= word_chars[i];
1454
718
}
1455
718
  YY_BREAK
1456
759
case 21:
1457
759
YY_RULE_SETUP
1458
759
#line 382 "libyara/re_lexer.l"
1459
759
{
1460
1461
25.0k
  for (int i = 0; i < 32; i++)
1462
24.2k
    LEX_ENV->re_class.bitmap[i] |= ~word_chars[i];
1463
759
}
1464
759
  YY_BREAK
1465
760
case 22:
1466
760
YY_RULE_SETUP
1467
760
#line 389 "libyara/re_lexer.l"
1468
760
{
1469
1470
25.0k
  for (int i = 0; i < 32; i++)
1471
24.3k
    LEX_ENV->re_class.bitmap[i] |= space_chars[i];
1472
760
}
1473
760
  YY_BREAK
1474
724
case 23:
1475
724
YY_RULE_SETUP
1476
724
#line 396 "libyara/re_lexer.l"
1477
724
{
1478
1479
23.8k
  for (int i = 0; i < 32; i++)
1480
23.1k
    LEX_ENV->re_class.bitmap[i] |= ~space_chars[i];
1481
724
}
1482
724
  YY_BREAK
1483
495
case 24:
1484
495
YY_RULE_SETUP
1485
495
#line 403 "libyara/re_lexer.l"
1486
495
{
1487
1488
5.44k
  for (char c = '0'; c <= '9'; c++)
1489
4.95k
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1490
495
}
1491
495
  YY_BREAK
1492
813
case 25:
1493
813
YY_RULE_SETUP
1494
813
#line 410 "libyara/re_lexer.l"
1495
813
{
1496
1497
26.8k
  for (int i = 0; i < 32; i++)
1498
26.0k
  {
1499
    // digits 0-7 are in the sixth byte of the vector, let that byte alone
1500
26.0k
    if (i == 6)
1501
813
      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
25.2k
    if (i == 7)
1506
813
      LEX_ENV->re_class.bitmap[i] |= 0xFC;
1507
24.3k
    else
1508
24.3k
      LEX_ENV->re_class.bitmap[i] = 0xFF;
1509
25.2k
  }
1510
813
}
1511
813
  YY_BREAK
1512
2.62k
case 26:
1513
2.62k
YY_RULE_SETUP
1514
2.62k
#line 428 "libyara/re_lexer.l"
1515
2.62k
{
1516
1517
2.62k
  uint8_t c;
1518
2.62k
  int return_code;
1519
1520
2.62k
  return_code = read_escaped_char(yyscanner, &c, LEX_ENV->strict_escape);
1521
2.62k
  if (return_code == VALID_ESCAPE_SEQUENCE)
1522
2.60k
  {
1523
2.60k
    LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8;
1524
2.60k
  }
1525
22
  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
22
  else
1531
22
  {
1532
22
    yyerror(yyscanner, lex_env, "illegal escape sequence");
1533
22
    yyterminate();
1534
22
  }
1535
2.62k
}
1536
2.60k
  YY_BREAK
1537
9.90k
case 27:
1538
9.90k
YY_RULE_SETUP
1539
9.90k
#line 451 "libyara/re_lexer.l"
1540
9.90k
{
1541
1542
9.90k
  if (yytext[0] >= 32 && yytext[0] < 127)
1543
9.87k
  {
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
9.87k
    LEX_ENV->re_class.bitmap[yytext[0] / 8] |= 1 << yytext[0] % 8;
1548
9.87k
  }
1549
32
  else
1550
32
  {
1551
32
    yyerror(yyscanner, lex_env, "non-ascii character");
1552
32
    yyterminate();
1553
32
  }
1554
9.90k
}
1555
9.87k
  YY_BREAK
1556
9.87k
case YY_STATE_EOF(char_class):
1557
45
#line 468 "libyara/re_lexer.l"
1558
45
{
1559
1560
  // End of regexp reached while scanning a character class.
1561
1562
45
  yyerror(yyscanner, lex_env, "missing terminating ] for character class");
1563
45
  yyterminate();
1564
9.90k
}
1565
0
  YY_BREAK
1566
248k
case 28:
1567
248k
YY_RULE_SETUP
1568
248k
#line 477 "libyara/re_lexer.l"
1569
248k
{
1570
1571
248k
  if (yytext[0] >= 32 && yytext[0] < 127)
1572
248k
  {
1573
248k
    return yytext[0];
1574
248k
  }
1575
0
  else
1576
0
  {
1577
0
    yyerror(yyscanner, lex_env, "non-ascii character");
1578
0
    yyterminate();
1579
0
  }
1580
248k
}
1581
0
  YY_BREAK
1582
25.7k
case YY_STATE_EOF(INITIAL):
1583
25.7k
#line 491 "libyara/re_lexer.l"
1584
25.7k
{
1585
1586
25.7k
  yyterminate();
1587
248k
}
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
52.0k
  case YY_END_OF_BUFFER:
1597
52.0k
    {
1598
    /* Amount of text matched not including the EOB char. */
1599
52.0k
    int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
1600
1601
    /* Undo the effects of YY_DO_BEFORE_ACTION. */
1602
52.0k
    *yy_cp = yyg->yy_hold_char;
1603
52.0k
    YY_RESTORE_YY_MORE_OFFSET
1604
1605
52.0k
    if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1606
25.8k
      {
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
25.8k
      yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1617
25.8k
      YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1618
25.8k
      YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1619
25.8k
      }
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
52.0k
    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
52.0k
    else switch ( yy_get_next_buffer( yyscanner ) )
1666
52.0k
      {
1667
25.8k
      case EOB_ACT_END_OF_FILE:
1668
25.8k
        {
1669
25.8k
        yyg->yy_did_buffer_switch_on_eof = 0;
1670
1671
25.8k
        if ( yywrap( yyscanner ) )
1672
25.8k
          {
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
25.8k
          yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
1683
1684
25.8k
          yy_act = YY_STATE_EOF(YY_START);
1685
25.8k
          goto do_action;
1686
25.8k
          }
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
25.8k
        }
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
26.2k
      case EOB_ACT_LAST_MATCH:
1707
26.2k
        yyg->yy_c_buf_p =
1708
26.2k
        &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
1709
1710
26.2k
        yy_current_state = yy_get_previous_state( yyscanner );
1711
1712
26.2k
        yy_cp = yyg->yy_c_buf_p;
1713
26.2k
        yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1714
26.2k
        goto yy_find_action;
1715
52.0k
      }
1716
0
    break;
1717
52.0k
    }
1718
1719
0
  default:
1720
0
    YY_FATAL_ERROR(
1721
2.21M
      "fatal flex scanner internal error--no action found" );
1722
2.21M
  } /* end of action switch */
1723
2.21M
    } /* end of scanning one token */
1724
2.14M
  } /* end of user's declarations */
1725
2.14M
} /* 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
52.1k
{
1736
52.1k
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1737
52.1k
  char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1738
52.1k
  char *source = yyg->yytext_ptr;
1739
52.1k
  int number_to_move, i;
1740
52.1k
  int ret_val;
1741
1742
52.1k
  if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
1743
0
    YY_FATAL_ERROR(
1744
52.1k
    "fatal flex scanner internal error--end of buffer missed" );
1745
1746
52.1k
  if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1747
52.1k
    { /* Don't try to fill the buffer, so this is an EOF. */
1748
52.1k
    if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
1749
25.8k
      {
1750
      /* We matched a single character, the EOB, so
1751
       * treat this as a final EOF.
1752
       */
1753
25.8k
      return EOB_ACT_END_OF_FILE;
1754
25.8k
      }
1755
1756
26.3k
    else
1757
26.3k
      {
1758
      /* We matched some text prior to the EOB, first
1759
       * process it.
1760
       */
1761
26.3k
      return EOB_ACT_LAST_MATCH;
1762
26.3k
      }
1763
52.1k
    }
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
52.1k
}
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
26.2k
{
1875
26.2k
  yy_state_type yy_current_state;
1876
26.2k
  char *yy_cp;
1877
26.2k
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1878
1879
26.2k
  yy_current_state = yyg->yy_start;
1880
1881
66.5k
  for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
1882
40.3k
    {
1883
40.3k
    YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1884
40.3k
    if ( yy_accept[yy_current_state] )
1885
456
      {
1886
456
      yyg->yy_last_accepting_state = yy_current_state;
1887
456
      yyg->yy_last_accepting_cpos = yy_cp;
1888
456
      }
1889
63.3k
    while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1890
22.9k
      {
1891
22.9k
      yy_current_state = (int) yy_def[yy_current_state];
1892
22.9k
      if ( yy_current_state >= 47 )
1893
22.9k
        yy_c = yy_meta[yy_c];
1894
22.9k
      }
1895
40.3k
    yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1896
40.3k
    }
1897
1898
26.2k
  return yy_current_state;
1899
26.2k
}
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
2.15M
{
1943
2.15M
  int c;
1944
2.15M
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1945
1946
2.15M
  *yyg->yy_c_buf_p = yyg->yy_hold_char;
1947
1948
2.15M
  if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
1949
131
    {
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
131
    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
131
    else
1959
131
      { /* need more input */
1960
131
      int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
1961
131
      ++yyg->yy_c_buf_p;
1962
1963
131
      switch ( yy_get_next_buffer( yyscanner ) )
1964
131
        {
1965
131
        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
131
          yyrestart( yyin , yyscanner);
1978
1979
          /*FALLTHROUGH*/
1980
1981
131
        case EOB_ACT_END_OF_FILE:
1982
131
          {
1983
131
          if ( yywrap( yyscanner ) )
1984
131
            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
131
#endif
1993
131
          }
1994
1995
0
        case EOB_ACT_CONTINUE_SCAN:
1996
0
          yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
1997
0
          break;
1998
131
        }
1999
131
      }
2000
131
    }
2001
2002
2.15M
  c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
2003
2.15M
  *yyg->yy_c_buf_p = '\0';  /* preserve yytext */
2004
2.15M
  yyg->yy_hold_char = *++yyg->yy_c_buf_p;
2005
2006
2.15M
  if ( c == '\n' )
2007
    
2008
0
    do{ yylineno++;
2009
0
        yycolumn=0;
2010
0
    }while(0)
2011
2.15M
;
2012
2013
2.15M
  return c;
2014
2.15M
}
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
131
{
2024
131
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2025
2026
131
  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
131
  yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
2033
131
  yy_load_buffer_state( yyscanner );
2034
131
}
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
26.2k
{
2042
26.2k
    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
26.2k
  yyensure_buffer_stack (yyscanner);
2050
26.2k
  if ( YY_CURRENT_BUFFER == new_buffer )
2051
0
    return;
2052
2053
26.2k
  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
26.2k
  YY_CURRENT_BUFFER_LVALUE = new_buffer;
2062
26.2k
  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
26.2k
  yyg->yy_did_buffer_switch_on_eof = 1;
2070
26.2k
}
2071
2072
static void yy_load_buffer_state  (yyscan_t yyscanner)
2073
52.7k
{
2074
52.7k
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2075
52.7k
  yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
2076
52.7k
  yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
2077
52.7k
  yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
2078
52.7k
  yyg->yy_hold_char = *yyg->yy_c_buf_p;
2079
52.7k
}
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
26.2k
{
2117
26.2k
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2118
2119
26.2k
  if ( ! b )
2120
0
    return;
2121
2122
26.2k
  if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
2123
26.2k
    YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
2124
2125
26.2k
  if ( b->yy_is_our_buffer )
2126
26.2k
    yyfree( (void *) b->yy_ch_buf , yyscanner );
2127
2128
26.2k
  yyfree( (void *) b , yyscanner );
2129
26.2k
}
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
131
{
2138
131
  int oerrno = errno;
2139
131
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2140
2141
131
  yy_flush_buffer( b , yyscanner);
2142
2143
131
  b->yy_input_file = file;
2144
131
  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
131
    if (b != YY_CURRENT_BUFFER){
2151
0
        b->yy_bs_lineno = 1;
2152
0
        b->yy_bs_column = 0;
2153
0
    }
2154
2155
131
        b->yy_is_interactive = 0;
2156
    
2157
131
  errno = oerrno;
2158
131
}
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
131
{
2166
131
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2167
131
  if ( ! b )
2168
0
    return;
2169
2170
131
  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
131
  b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
2177
131
  b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
2178
2179
131
  b->yy_buf_pos = &b->yy_ch_buf[0];
2180
2181
131
  b->yy_at_bol = 1;
2182
131
  b->yy_buffer_status = YY_BUFFER_NEW;
2183
2184
131
  if ( b == YY_CURRENT_BUFFER )
2185
131
    yy_load_buffer_state( yyscanner );
2186
131
}
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
26.2k
{
2227
26.2k
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2228
26.2k
  if (!YY_CURRENT_BUFFER)
2229
26.2k
    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
26.2k
{
2247
26.2k
  yy_size_t num_to_alloc;
2248
26.2k
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2249
2250
26.2k
  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
26.2k
      num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
2257
26.2k
    yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
2258
26.2k
                (num_to_alloc * sizeof(struct yy_buffer_state*)
2259
26.2k
                , yyscanner);
2260
26.2k
    if ( ! yyg->yy_buffer_stack )
2261
0
      YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2262
2263
26.2k
    memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
2264
2265
26.2k
    yyg->yy_buffer_stack_max = num_to_alloc;
2266
26.2k
    yyg->yy_buffer_stack_top = 0;
2267
26.2k
    return;
2268
26.2k
  }
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
26.2k
{
2297
26.2k
  YY_BUFFER_STATE b;
2298
    
2299
26.2k
  if ( size < 2 ||
2300
26.2k
       base[size-2] != YY_END_OF_BUFFER_CHAR ||
2301
26.2k
       base[size-1] != YY_END_OF_BUFFER_CHAR )
2302
    /* They forgot to leave room for the EOB's. */
2303
0
    return NULL;
2304
2305
26.2k
  b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
2306
26.2k
  if ( ! b )
2307
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
2308
2309
26.2k
  b->yy_buf_size = (int) (size - 2);  /* "- 2" to take care of EOB's */
2310
26.2k
  b->yy_buf_pos = b->yy_ch_buf = base;
2311
26.2k
  b->yy_is_our_buffer = 0;
2312
26.2k
  b->yy_input_file = NULL;
2313
26.2k
  b->yy_n_chars = b->yy_buf_size;
2314
26.2k
  b->yy_is_interactive = 0;
2315
26.2k
  b->yy_at_bol = 1;
2316
26.2k
  b->yy_fill_buffer = 0;
2317
26.2k
  b->yy_buffer_status = YY_BUFFER_NEW;
2318
2319
26.2k
  yy_switch_to_buffer( b , yyscanner );
2320
2321
26.2k
  return b;
2322
26.2k
}
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
26.2k
{
2334
    
2335
26.2k
  return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
2336
26.2k
}
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
26.2k
{
2347
26.2k
  YY_BUFFER_STATE b;
2348
26.2k
  char *buf;
2349
26.2k
  yy_size_t n;
2350
26.2k
  int i;
2351
    
2352
  /* Get memory for full buffer, including space for trailing EOB's. */
2353
26.2k
  n = (yy_size_t) (_yybytes_len + 2);
2354
26.2k
  buf = (char *) yyalloc( n , yyscanner );
2355
26.2k
  if ( ! buf )
2356
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
2357
2358
4.37M
  for ( i = 0; i < _yybytes_len; ++i )
2359
4.34M
    buf[i] = yybytes[i];
2360
2361
26.2k
  buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2362
2363
26.2k
  b = yy_scan_buffer( buf, n , yyscanner);
2364
26.2k
  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
26.2k
  b->yy_is_our_buffer = 1;
2371
2372
26.2k
  return b;
2373
26.2k
}
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
96.8k
{
2411
96.8k
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2412
96.8k
    return yyextra;
2413
96.8k
}
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
26.2k
{
2484
26.2k
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2485
26.2k
    yyextra = user_defined ;
2486
26.2k
}
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
26.2k
{
2570
26.2k
    if (ptr_yy_globals == NULL){
2571
0
        errno = EINVAL;
2572
0
        return 1;
2573
0
    }
2574
2575
26.2k
    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
2576
2577
26.2k
    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
26.2k
    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2584
2585
26.2k
    return yy_init_globals ( *ptr_yy_globals );
2586
26.2k
}
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
52.5k
{
2624
52.5k
    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
52.5k
    yyg->yy_buffer_stack = NULL;
2630
52.5k
    yyg->yy_buffer_stack_top = 0;
2631
52.5k
    yyg->yy_buffer_stack_max = 0;
2632
52.5k
    yyg->yy_c_buf_p = NULL;
2633
52.5k
    yyg->yy_init = 0;
2634
52.5k
    yyg->yy_start = 0;
2635
2636
52.5k
    yyg->yy_start_stack_ptr = 0;
2637
52.5k
    yyg->yy_start_stack_depth = 0;
2638
52.5k
    yyg->yy_start_stack =  NULL;
2639
2640
/* Defined in main.c */
2641
#ifdef YY_STDINIT
2642
    yyin = stdin;
2643
    yyout = stdout;
2644
#else
2645
52.5k
    yyin = NULL;
2646
52.5k
    yyout = NULL;
2647
52.5k
#endif
2648
2649
    /* For future reference: Set errno on error, since we are called by
2650
     * yylex_init()
2651
     */
2652
52.5k
    return 0;
2653
52.5k
}
2654
2655
/* yylex_destroy is for both reentrant and non-reentrant scanners. */
2656
int yylex_destroy  (yyscan_t yyscanner)
2657
26.2k
{
2658
26.2k
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2659
2660
    /* Pop the buffer stack, destroying each element. */
2661
52.5k
  while(YY_CURRENT_BUFFER){
2662
26.2k
    yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
2663
26.2k
    YY_CURRENT_BUFFER_LVALUE = NULL;
2664
26.2k
    yypop_buffer_state(yyscanner);
2665
26.2k
  }
2666
2667
  /* Destroy the stack itself. */
2668
26.2k
  yyfree(yyg->yy_buffer_stack , yyscanner);
2669
26.2k
  yyg->yy_buffer_stack = NULL;
2670
2671
    /* Destroy the start condition stack. */
2672
26.2k
        yyfree( yyg->yy_start_stack , yyscanner );
2673
26.2k
        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
26.2k
    yy_init_globals( yyscanner);
2678
2679
    /* Destroy the main struct (reentrant only). */
2680
26.2k
    yyfree ( yyscanner , yyscanner );
2681
26.2k
    yyscanner = NULL;
2682
26.2k
    return 0;
2683
26.2k
}
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
105k
{
2714
105k
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2715
105k
  (void)yyg;
2716
105k
  return malloc(size);
2717
105k
}
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
131k
{
2736
131k
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2737
131k
  (void)yyg;
2738
131k
  free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
2739
131k
}
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
753k
{
2751
753k
  unsigned int hex_value;
2752
753k
  char hex[3];
2753
2754
753k
  assert(text[0] == '\\');
2755
2756
753k
  switch(text[1])
2757
753k
  {
2758
702k
  case 'x':
2759
702k
    if (!isxdigit(text[2]) || !isxdigit(text[3]))
2760
43
      return 0;
2761
702k
    hex[0] = text[2];
2762
702k
    hex[1] = text[3];
2763
702k
    hex[2] = '\0';
2764
702k
    sscanf(hex, "%x", &hex_value);
2765
702k
    *value = (uint8_t) hex_value;
2766
702k
    break;
2767
2768
418
  case 'n':
2769
418
    *value = '\n';
2770
418
    break;
2771
2772
390
  case 't':
2773
390
    *value = '\t';
2774
390
    break;
2775
2776
180
  case 'r':
2777
180
    *value = '\r';
2778
180
    break;
2779
2780
207
  case 'f':
2781
207
    *value = '\f';
2782
207
    break;
2783
2784
721
  case 'a':
2785
721
    *value = '\a';
2786
721
    break;
2787
2788
  // Support metacharacters in escape sequences
2789
17.6k
  case '\\':
2790
19.6k
  case '^':
2791
21.7k
  case '$':
2792
27.4k
  case '.':
2793
27.6k
  case '|':
2794
28.1k
  case '(':
2795
28.6k
  case ')':
2796
29.1k
  case '[':
2797
30.1k
  case ']':
2798
2799
  // Support other special characters that are used in rules and need to be escaped
2800
30.3k
  case '*':
2801
34.9k
  case '+':
2802
37.6k
  case '?':
2803
37.7k
  case '"':
2804
38.1k
  case '\'':
2805
38.6k
  case '-':
2806
40.0k
  case '{':
2807
41.7k
  case '}':
2808
42.1k
  case '#':
2809
42.3k
  case ':':
2810
42.5k
  case '_':
2811
42.7k
  case '=':
2812
42.7k
  case '/':
2813
43.1k
  case '!':
2814
44.5k
  case ',':
2815
45.0k
  case '@':
2816
45.6k
  case '<':
2817
45.7k
  case '>':
2818
45.9k
  case '~':
2819
46.5k
  case '&':
2820
47.0k
  case '%':
2821
47.0k
    *value = text[1];
2822
47.0k
    break;
2823
2.12k
  default:
2824
2.12k
    *value = text[1];
2825
2.12k
    if (strict_escape)
2826
0
      return UNKNOWN_ESCAPE_SEQUENCE;
2827
2.12k
    return VALID_ESCAPE_SEQUENCE;
2828
753k
  }
2829
2830
751k
  return VALID_ESCAPE_SEQUENCE;
2831
753k
}
2832
2833
2834
#ifdef __cplusplus
2835
#define RE_YY_INPUT yyinput
2836
#else
2837
2.15M
#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
752k
{
2846
752k
  char text[4] = {0, 0, 0, 0};
2847
2848
752k
  text[0] = '\\';
2849
752k
  text[1] = RE_YY_INPUT(yyscanner);
2850
2851
752k
  if (text[1] == EOF || text[1] == 0)
2852
14
    return 0;
2853
2854
752k
  if (text[1] == 'x')
2855
701k
  {
2856
701k
    text[2] = RE_YY_INPUT(yyscanner);
2857
2858
701k
    if (text[2] == EOF || text[2] == 0)
2859
36
      return 0;
2860
2861
701k
    text[3] = RE_YY_INPUT(yyscanner);
2862
2863
701k
    if (text[3] == EOF || text[3] == 0)
2864
144
      return 0;
2865
701k
  }
2866
2867
752k
  return escaped_char_value(text, escaped_char, strict_escape);
2868
752k
}
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
917
{
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
917
  if (lex_env->last_error == ERROR_SUCCESS || lex_env->last_error == ERROR_UNKNOWN_ESCAPE_SEQUENCE)
2899
554
  {
2900
554
    lex_env->last_error = ERROR_INVALID_REGULAR_EXPRESSION;
2901
2902
554
    strlcpy(
2903
554
        lex_env->last_error_message,
2904
554
        error_message,
2905
554
        sizeof(lex_env->last_error_message));
2906
554
  }
2907
917
}
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
26.2k
{
2934
26.2k
  yyscan_t yyscanner;
2935
26.2k
  jmp_buf recovery_trampoline;
2936
26.2k
  RE_LEX_ENVIRONMENT lex_env;
2937
2938
26.2k
  lex_env.last_error = ERROR_SUCCESS;
2939
26.2k
  if (flags & RE_PARSER_FLAG_ENABLE_STRICT_ESCAPE_SEQUENCES)
2940
0
    lex_env.strict_escape = true;
2941
26.2k
   else
2942
26.2k
    lex_env.strict_escape = false;
2943
26.2k
  lex_env.last_error_message[0] = '\0';
2944
2945
26.2k
  yr_thread_storage_set_value(
2946
26.2k
      &yr_yyfatal_trampoline_tls,
2947
26.2k
      &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
26.2k
  if (setjmp(recovery_trampoline) != 0)
2952
0
    return ERROR_INTERNAL_FATAL_ERROR;
2953
2954
26.2k
  FAIL_ON_ERROR(yr_re_ast_create(re_ast));
2955
2956
26.2k
  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
26.2k
  yyset_extra(*re_ast, yyscanner);
2964
26.2k
  yy_scan_string(re_string, yyscanner);
2965
2966
26.2k
  yyparse(yyscanner, &lex_env);
2967
26.2k
  yylex_destroy(yyscanner);
2968
2969
26.2k
  if (lex_env.last_error != ERROR_SUCCESS)
2970
554
  {
2971
554
    if (lex_env.last_error != ERROR_UNKNOWN_ESCAPE_SEQUENCE)
2972
554
    {
2973
554
      yr_re_ast_destroy(*re_ast);
2974
554
      *re_ast = NULL;
2975
554
    }
2976
2977
554
    strlcpy(
2978
554
        error->message,
2979
554
        lex_env.last_error_message,
2980
554
        sizeof(error->message));
2981
2982
554
    return lex_env.last_error;
2983
554
  }
2984
2985
25.7k
  return ERROR_SUCCESS;
2986
26.2k
}
2987